简体   繁体   English

正则表达式国际格式的电话号码

[英]Regex for phone number in international format

I need to write a regex that will match only this formats 我需要编写一个仅与这种格式匹配的正则表达式

+420 000 000 000
+420000000000
420 000 000 000
420000000000

It can't match any az character in any part of string, just numbers, white space and "+" on the beginning. 它不能与字符串的任何部分中的任何az字符匹配,只能与数字,空格和开头的“ +”匹配。

You could try the below regex, 您可以尝试以下正则表达式,

^\+?\d{3} ?\d{3} ?\d{3} ?\d{3}$

DEMO 演示

  • ^ Asserts that we are at the start. ^断言我们是开始。
  • \\+? optional + 可选+
  • \\d{3} Matches exactly three digits. \\d{3}精确匹配三个数字。
  • <space>? optional space 可选空间
  • $ Asserts that we are at the end. $断言我们已经结束了。

This regex should work for you: 此正则表达式应为您工作:

$mobileNumber = "0905 222 222";

 if ( preg_match("/^(\+?)([0-9] ?){9,20}$/", $mobileNumber) )
            echo "matches!";

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM