我需要一个正则表达式,其中至少包含以下五个字符类中的两个:
- 小写字母
- 大写字母
- 数字
- 标点符号
- “特殊”字符(例如
@#$%^&*()_ + |〜-= \
{} []:“;'<>/`等)
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++;
但是 Char.IsSymbol 在 @ % & $ . ? 等字符上返回 false。
而通过正则表达式:
Regex Expression = new Regex("({(?=.*[a-z])(?=.*[A-Z]).{8,}}|{(?=.*[A-Z])(?!.*\\s).{8,}})");
bool test= Expression.IsMatch(txtBoxPass.Text);
但我需要一个带有“OR”条件的单一正则表达式。
1a
是一个有效的密码。 - Tim Pietzckeré
或ß
或Ä
是字母? - Tim Pietzcker