Click here to Skip to main content
15,924,452 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Using java script How to validate the password in asp.net c#


I want some characters,numbers,Special characters,
Posted
Updated 2-Sep-12 22:24pm
v3
Comments
lukeer 3-Sep-12 3:59am    
Don't post the same question again[^]. Use the "Improve question" link instead. It's located directly beneath your original question. Provide further information to help others to help you.

C#
try this reg expression

/^([a-zA-Z0-9~!@#$%^&*]*)$/
 
Share this answer
 
 
Share this answer
 
Comments
Shibiny 3-Sep-12 4:24am    
Using java script How to validate the password in asp.net c#


I want some characters,numbers,Special characters,
This is what I did some time back. A simple point based approach.

JavaScript
function CheckPassword()
       {
           var password = document.getElementById('<%=txtPassword.ClientID %>').value;
           var txtPassword = document.getElementById('<%=lblPasswordMeter.ClientID %>');

           var score = 0;

           if(password.length < 8)
           {
               //this is a very weak password
               txtPassword.style.color = "Red";
               txtPassword.innerHTML = "Too short";
               return;

           }

           //lets check for small letters
           for(var s=0; s<password.length; ++s)
           {
               if(password.charCodeAt(s) >= 'a'.charCodeAt(0) && password.charCodeAt(s) <= 'z'.charCodeAt(0))
               {
                   score += 1;
                   break;
               }
           }

           //lets check for capital letters
           for(var s=0; s<password.length; ++s)
           {
               if(password.charCodeAt(s) >= 'A'.charCodeAt(0) && password.charCodeAt(s) <= 'Z'.charCodeAt(0))
               {
                   score += 1;
                   break;
               }
           }

           //Lets check for numbers
           for(var s=0; s<password.length; ++s)
           {
               if(password.charCodeAt(s) >= '0'.charCodeAt(0) && password.charCodeAt(s) <= '9'.charCodeAt(0))
               {
                   score += 1;
                   break;
               }
           }

          //lets now calculate final score to declare the results
          switch(score)
          {
           case 0:
           case 1:
               txtPassword.style.color = "Red";
               txtPassword.innerHTML = "too weak";
           break;
           case 2:
               txtPassword.style.color = "Orange";
               txtPassword.innerHTML = "average";
           break;
           case 3:
               txtPassword.style.color = "Green";
               txtPassword.innerHTML = "strong";
           break;
          }
       };
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900