我使用下面的正则表达式来覆盖国际电话号码&一些只能采用这种格式的本地电话号码。
国际电话号码
+123 456789123
+123456789123
+12 3456789123
+123456789123本地电话号码格式(手机号码)。其次是固定电话号码)
1234567890
123 4567890
123123456
12 3123456正则表达式,我正在使用
^[\+]{0,1}[1-9]{1}[0-9]{7,11}$这个正则表达式只适用于国际数字,而不管是否添加了前缀+,但不允许任何时间间隔字符。
我希望它支持上述格式,例如,也应该支持所有国际电话号码。
我正在研究asp.net,以防万一有人想知道。
更新:
最后,我使用了下面的Regex,它也处理扩展
^([\+]?[0-9]{1,3}[\s.-][0-9]{1,12})([\s.-]?[0-9]{1,4}?)$发布于 2013-09-03 05:20:45
嗨,一些关于你的评论
[\+]{0,1} could be \+? // easier to read, + as optional
[1-9]{1} could be writen as [1-9]
[0-9]{7,11} should be [0-9\s.-]{7,11} // phone numbers van contain - or .你完全可以
^\+?[1-9][0-9\s.-]{7,11}$电话号码可以写成
第二次尝试
你可以分两步解决你的问题:
第一场比赛可能性电话号码从11增加到20。
^\+?[1-9][0-9\s.-]{7,20}$
下一步是删除非数字,并验证长度介于8和12之间。
string phone = "070.3233123";
string onlyNumbers= new String(phone.ToCharArray().Where(c => Char.IsDigit(c)).ToArray());
if (onlyNumbers.length > 8 && onlyNumbers.length < 12)
{
// we got a winner
}发布于 2015-01-20 13:14:12
下面的模式将验证以下格式
^\s*\+?[0-9]\d?[- .]?(\([2-9]\d{2}\)|[2-9]\d{2})[- .]?\d{3}[- .]?\d{4}$结果
+1 (281) 388 0388
+65 281 388-0388
+91 281 388 0388
+65 2813880388
+652813880388
+65(281)3880388
+65281388-0388
+1281388-0388https://stackoverflow.com/questions/18584492
复制相似问题