Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / programming / regular-expression

ASP.NET Password Strength Regular Expression

5.00/5 (6 votes)
5 Jan 2011CPOL 38.5K  
ASP.NET Password Strength Regular Expression. Customize n numbers of upper case, digits, special characters.


Shown below is the regular expression for password strength with n number of digits, upper case, special characters and at least 12 characters in length.



(?=^.{12,25}$)(?=(?:.*?\d){2})(?=.*[a-z])(?=(?:.*?[A-Z]){2})(?=(?:.*?[!@#$%*()_+^&}{:;?.]){1})(?!.*\s)[0-9a-zA-Z!@#$%*()_+^&]*$


Explanation


(?=^.{12,25}$) -- password length range from 12 to 25, the numbers are adjustable 

(?=(?:.*?[!@#$%*()_+^&}{:;?.]){1}) -- at least 1 special characters (!@#$%*()_+^&}{:;?.}) , the number is adjustable 

(?=(?:.*?\d){2}) -- at least 2 digits, the number is adjustable 

(?=.*[a-z]) -- characters a-z 

  (?=(?:.*?[A-Z]){2}) -- at least 2 upper case characters, the number is adjustable 

License

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