0
我需要一个函数来返回给定的字符串是否至少包含x个特殊字符。限制密码至少包含x个特殊字符?
我宁愿它不应该硬编码。
伪代码:
public bool IsValid(string password, int minSpecialCharacters)
{
if (!string.IsNullOrWhiteSpace(password))
return
password.Count(c => char.IsSpecialCharacter(c)) < minSpecialCharacters;
return true;
}
而像这样的语言会怎样? – 2011-02-27 22:02:08
有一个简单的解决方案:将所有非字母数字(即[[^ A-Za-z0-9])都视为特殊字符。用字符串计数它们也很简单。 – Artefact2 2011-02-27 22:10:43
@ Arefact2我不明白你为什么不发布这个答案,你想让别人来做它,并获得你的声誉!? – Shimmy 2011-02-28 02:16:07