这项工作?
string characters = " -/:[email protected][-`{-~À-ÿ";
string letters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
string[] inputs = {
"AABBCCDD",
"aaaaaaaa",
"11111111",
"a1a1a1a1",
"[email protected]@@@AA",
"A1C EKFE",
"AADE F"
};
foreach (string input in inputs)
{
var counts = input.Cast<char>().Select(x => new { ch = characters.Contains(x.ToString()) ? 1 : 0, letter = letters.Contains(x.ToString()) ? 1 : 0, notmatch = (characters + letters).Contains(x) ? 0 : 1}).ToArray();
Boolean isMatch = (input.Length >= 8) && (input.Length <= 30) && (counts.Sum(x => x.notmatch) == 0) && (counts.Sum(x => x.ch) <= 3);
Console.WriteLine("Input : '{0}', Matches : '{1}'", input, isMatch ? "Match" : "No Match");
}
Console.ReadLine();
我的提示是让用户尽可能多地使用他想要的特殊字符 –
为什么你想要正则表达式?在计算字符数方面,这并不好。当然,你可以做到这一点,但这是一种痛苦,很难理解或维护。只需使用一些'IndexOf'或'String.Contains',你就完成了。 – HimBromBeere
@RomanoZumbé没有选择。 – Szadek35