Regular Expression for password validation

The following regular expression is for a 4 to 8 char password and containing at least an alphabet and one Number. You can change numbers in the end to your allowed password length.

private bool IsValidPassword(string strPassword)
{
Regex compareRegex = new Regex(@"(?!^[0-9]*$)(?!^[a-zA-Z]*$)^([a-zA-Z0-9]{6,15})$");
if (compareRegex.IsMatch(strPassword))
{
return true;
}
else
{
return false;
}
}


Comments

Author: Manindra Kumar Upadhyay09 Apr 2010 Member Level: Gold   Points : 1

try this link:
http://www.manindra.net/post/2010/04/09/AspNet-Regular-Expressions.aspx



  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email: