Monday, October 5, 2009

Regular expression for password


Regular expression for password check:

1. ^.*(?=.{8,10}) (?=.*[a-zA-Z0-9]).*$
This password RegEx will check length between 8 to 10 characters, which includes alphabets either uppercase or lowercase and digits.

2. ^.*(?=.{8,10})(?=.*\d)(?=.*[a-zA-Z]).*$
This password RegEx will check length between 8 to 10 characters, minimum one digit and minimum one alphabet either uppercase or lowercase. It doesn’t allow any special characters.

3. ^.*(?=.{8,})(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[@#$%^&+=]).*$
This password RegEx will check minimum length of 8 characters, minimum one 2 digits, minimum one lowercase alphabet, minimum one uppercase alphabets and minimum one occurance of special character.

4. ^.*(?=.{8,20})(?=(?:.*?\d){2})(?=(?:.*?[a-zA-Z]){2})(?=.*[!@#$%^&\*+=\\?]{0,}).*$
Or
^.*(?=.{8,20})(?=.*\d{2,})(?=.*[a-zA-Z]{2,})(?=.*[!@#$%^&\*+=\\?]{0,}).*$
This password RegEx will check length between 8 to 20 characters, minimum no of 2 digits, minimum of 2 alphabets either uppercase or lower case and zero or more occurances of special characters.

Basic terminology: http://www.regular-expressions.info/reference.html
Download: http://www.radsoftware.com.au/regexdesigner/
Msdn Link: http://msdn.microsoft.com/en-us/library/ms972966.aspx