I need a regular expression that Contain at least two of the five following character classes:
- Lower case characters
- Upper case characters
- Numbers
- Punctuation
- “Special” characters (e.g.
@#$%^&*()_+|~-=
{}[]:";'<>/` etc.)
This is I have done so far
int upperCount = 0;
int lowerCount = 0;
int digitCount = 0;
int symbolCount = 0;
for (int i = 0; i < password.Length; i++)
{
if (Char.IsUpper(password[i]))
upperCount++;
else if (Char.IsLetter(password[i]))
lowerCount++;
else if (Char.IsDigit(password[i]))
digitCount++;
else if (Char.IsSymbol(password[i]))
symbolCount++;
but Char.IsSymbol is returning false on @ % & $ . ? etc..
and through regex
Regex Expression = new Regex("({(?=.*[a-z])(?=.*[A-Z]).{8,}}|{(?=.*[A-Z])(?!.*\s).{8,}})");
bool test= Expression.IsMatch(txtBoxPass.Text);
but I need a single regular expression with "OR" condition.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…