[英]Regex : Matching phone numbers starting with NNN and having 10 numbers
I need to match phone numbers that : 我需要匹配以下电话号码:
start with 010 or 012 or 016 or 019 以010或012或016或019开头
Consist of 10 numbers exactly 完全由10个数字组成
Can you please help me on how to match numbers using PHP and regex? 您能帮我如何使用PHP和regex匹配数字吗?
return preg_match('/^01[0269]\\d{7}$/', $theStringToTest);
This will match 0, 1, one of (0, 2, 6, 9), and then any 7 numbers (3+7==10). 这将匹配0、1,(0、2、6、9)中的一个,然后匹配任意7个数字(3 + 7 == 10)。 The ^
means start of string and $
means end of string. ^
表示字符串的开头, $
表示字符串的结尾。
使用此正则表达式
/\b(010|012|016|019)[0-9]{7}\b/g
我想我会使用^01[0269][0-9]{7}$
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.