How to Replace Character from a String in Jquery

  To replace a specific Character from String with other character or number in Jquery we have to     use   regular expression.

  Lets See


How?



   
  var data="pqrst$vw"

   Here we have string data in which we have to replace "$" with     Character "u"


  So to do that


  we will write


  var replaceddata = data.replace(/$/g, 'u')






So in return we will get



  
  replaceddata="pqrstuv"


Conclusion 


Basically we use replace in jquery to stop passing any other unwanted  input from keyboard or to filter the data with correct digit or character.






How to reverse a string in C# and Jquery

To reverse  a string in C# we will use while Loop

Lets see how


  C#


    Public dynamic Reversestring(){
      string data="pqrstuvwxyz"    

            string reverse = "";
            int Length = 0;

            Length = EncodedDasboardData.Length - 1;
            while (Length >= 0)
            {
                reverse = reverse + EncodedDasboardData[Length];
                Length--;
               

            }

    return  reverse 
   }


Below in the return we will get



   reverse ="zyxwvutsrqp"


 Jquery

   
   var data='pqrstuvwxyz'
   var reverse=  data.split(' ').reverse().join('')

    reverse ="zyxwvutsrqp"

How to make Password Strong in jquery


The most important thing in a software is the Password which must be strong .To make Password strong we basically use Special Character,

Lets see how to check whether the entered Password by user is Strong or not in jquery.

Below is the span where we check the status of Password whether it is strong or not



 <span id="result"></span>


Below in the Password input Field we will get the value in a function name checkStrength();



 $('#result').html(checkStrength($('#Password').val()))



Below is the Function that give the Status of the Password


   
   function checkStrength(password) {
    var strength = 0
    Pstrength = 0;

   
    if (password.length < 6) {
        $('#result').removeClass()
        $('#result').addClass('short')
        return 'Too short'
    }

 
    if (password.length > 7) strength += 1


    if (password.match(/([a-z].*[A-Z])|([A-Z].*[a-z])/)) strength += 1


    if (password.match(/([a-zA-Z])/) && password.match(/([0-9])/)) strength += 1


    if (password.match(/([!,%,&,@,#,$,^,*,?,_,~])/)) strength += 1


    if (password.match(/(.*[!,%,&,@,#,$,^,*,?,_,~].*[!,",%,&,@,#,$,^,*,?,_,~])/)) {
        strength += 1

    }



    if (strength < 2) {
        $('#result').removeClass()
        $('#result').addClass('weak')
        return 'Weak'
    } else if (strength == 2) {
        $('#result').removeClass()
        $('#result').addClass('good')
        Pstrength = 1;
        return 'Good'
    } else {
        $('#result').removeClass()
        $('#result').addClass('strong')
        Pstrength = 1;
        return 'Strong'

    }
 }


In Result Span with (id =result) we will get the Status of the Password.

We can use CSS as given below


    <style>

        #register { margin-left:100px; }
        #register label{ margin-right:5px; } 
        #register input { padding:5px 7px; border:1px solid #d5d9da; box-shadow: 0 0 5px #e8e9eb  inset; width:250px; font-size:1em; outline:0; }
        #result{ margin-left:5px; } 
        #register .short{ color:#FF0000; } 
        #register .weak{ color:#E66C2C; }
        #register .good{ color:#2D98F3; } 
        #register .strong{ color:#006400; }


     </style>

How to Generate OTP in Asp.net C#


To Generate One time password (OTP) in Asp.net C# . We have to use  use For Loop with Numbers and need to use random Class.

Lets See how to generate OTP

we have number from 0-9  in string numbers to which we will use Loop.



  string numbers = "1234567890";

  string otp= string.Empty;

  string characters = numbers;
   characters += numbers;




       int length = 6;

 We take length as per number of digit of the OTP requirement.

 Now in For loop we will use the number as per its Length



             for (int i = 0; i < length; i++)
                {
                    string character = string.Empty;
                    do
                    {
                        int index = new Random().Next(0,   characters.Length);
                        character = characters.ToCharArray()     [index].ToString();
                    }
                    while (otp.IndexOf(character) != -1);
                     otp+= character;

                }



we will get the otp in return

Over All Codes below



 public dynamic generateotp()
        {
    string numbers = "1234567890";

                string characters = numbers;
               
                characters += numbers;
                int length = 6;
                string otp = string.Empty;
                for (int i = 0; i < length; i++)
                {
                    string character = string.Empty;
                    do
                    {
                        int index = new Random().Next(0, characters.Length);
                        character = characters.ToCharArray()[index].ToString();
                    } 
while (otp.IndexOf(character) != -1);
                    otp += character;


                }
      return otp 
  }

How to run a method after a specific time interval?

 To Run A method after a specific time interval in C# we have to use Timespan and threading  i.e

using System.Threading.Tasks;

Lets see How we will use it


   Task.Delay(new TimeSpan(hour, min, sec)).ContinueWith(o => { Your method() });


TimeSpan (hour, min, sec) here we will use the time when we supposed to hit the method.

In the Continue with we will add our method with whatever the Parameter we have.

We can also use 



         Task.Factory.StartNew(() =>
                {
                System.Threading.Thread.Sleep(1000);
               Your method()

          });


From both Process we can hit any method after a specific time interval.