using System;
using System.Text.RegularExpressions;
namespace ConsoleApplication1
{
class Program
{
static void Main()
{
var regexTelephone = new Regex(@"^(0[0-9]{2,3}\-)?([2-9][0-9]{6,7})+(\-[0-9]{1,4})?$");
var regexMobilePhone = new Regex(@"^[1][358]\d{9}$");
while (true)
{
Console.Write("Phone:");
var inputString = Console.ReadLine();
if (string.IsNullOrWhiteSpace(inputString)) continue;
if (regexTelephone.IsMatch(inputString) || regexMobilePhone.IsMatch(inputString))
{
Console.WriteLine("Okay!");
break;
}
Console.WriteLine("Wrong!");
}
Console.Write("Press any key to exit...");
Console.ReadKey();
}
}
}
正则表达式 验证输入为电话号码或手机
最新推荐文章于 2023-01-12 23:06:29 发布
