Tuesday, October 12, 2010

Regular Expression for Password

^(?=.{8,30})(?=.*[^A-Za-z])(?=.*[A-Z])(?=.*[a-z]).*

This means following:-

^ = starting from the beginning of the string...
(?=.{8,30}) = there is a string that is at least 8 characters long... (the upper bound of 30 cannot work this way)
(?=.*[^A-Za-z]) = somewhere in the string, there is at least one non-alphabetic character...
(?=.*[A-Z]) = somewhere in the string, there is at least one uppercase character...
(?=.*[a-z]) = somewhere in the string, there is at least one lowercase character....

.* match anyting, provided that all the above conditions are met.

No comments:

Post a Comment