📅  最后修改于: 2022-03-11 14:56:41.379000             🧑  作者: Mango
Copy CodeRegex reg = new Regex(@"^[0-9]{10}$");
string inputOK = "9876543214";
string inputBad1 = "876543214";
string inputBad2 = "09876543214";
if (reg.IsMatch(inputOK)) Console.WriteLine("OK");
if (!reg.IsMatch(inputBad1)) Console.WriteLine("OK");
if (!reg.IsMatch(inputBad2)) Console.WriteLine("OK");