Click here to Skip to main content
Sign Up to vote bad
good
See more: .NET
Using java script How to validate the password in asp.net c#

 
I want some characters,numbers,Special characters,
Posted 2 Sep '12 - 21:34
Shibiny555
Edited 2 Sep '12 - 22:24

Comments
lukeer - 3 Sep '12 - 3:59
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.

3 solutions

  Permalink  
Comments
Shibiny - 3 Sep '12 - 4:24
Using java script How to validate the password in asp.net c# I want some characters,numbers,Special characters,
try this reg expression
 
/^([a-zA-Z0-9~!@#$%^&*]*)$/
  Permalink  
This is what I did some time back. A simple point based approach.
 
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;
          }
       };
  Permalink  

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

  Print Answers RSS
Your Filters
Interested
Ignored
     
0 Sergey Alexandrovich Kryukov 419
1 Mahesh Bailwal 343
2 CPallini 245
3 Maciej Los 230
4 Aarti Meswania 173
0 Sergey Alexandrovich Kryukov 9,162
1 OriginalGriff 7,194
2 CPallini 3,923
3 Rohan Leuva 3,176
4 Maciej Los 2,633


Advertise | Privacy | Mobile
Web01 | 2.6.130516.1 | Last Updated 3 Sep 2012
Copyright © CodeProject, 1999-2013
All Rights Reserved. Terms of Use
Layout: fixed | fluid