[英]PHP - Regular Expression For Custom Phone Number Format
I need to validate phone number with following rule 我需要按照以下规则验证电话号码
I am facing difficulty to construct the correct regular expression, so far I only have preg_match('/^\\+\\d+$/', $value)
and this is definitely not working. 我在构造正确的正则表达式时遇到了困难,到目前为止,我只具有preg_match('/^\\+\\d+$/', $value)
,这绝对是行不通的。 Any help in here is appreciated. 在这里的任何帮助表示赞赏。
Thanks. 谢谢。
你可以使用正则表达式
^\+(?:(?:91)|(?:49)|(?:3(?:52)|3|2))\d{8,15}
Must be minimum 8 characters and maximum 15 最少8个字符,最多15个字符
I'm assuming this is total count. 我假设这是总数。
Pattern: 图案:
^\\+(?=\\d{8,15}$)(?:32|33|49|91|352)\\d+$
^ // start of line
\+ // a plus
(?=\d{8,15}$) // look ahead and assert 8 to 15 digits must match
(?: // grouped alternation (uncaptured)
32|33|49|91|352 // alternations
) // end of group
\d+ // 1 or more digits
$ // end of line
Your regular expression should look like this one: 您的正则表达式应如下所示:
^\+(352|91|33|49|32)(\d{8,15})$
This page https://regex101.com/ is very helpful for verify and describing regular expressions. https://regex101.com/的页面对于验证和描述正则表达式非常有用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.