您的位置:首页 > 其它

正则表达式 验证输入为电话号码或手机

2016-04-09 15:34 337 查看
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();
}
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: