什么正则表达式匹配所有国际移动电话号码

时间:2019-03-13 09:11:28

标签: javascript regex

我想验证手机号码字段。我根据自己的需求尝试了许多正则表达式

匹配案例

  1. (923)(423)(34455)
  2. 945 443 4442
  3. 919774744323
  4. +92 332 45 666
  5. 9144565
  6. 91-877-3655

我需要根据我的匹配情况使用正则表达式。

1 个答案:

答案 0 :(得分:1)

尝试一下:

^[+]?(?:\d+|(?:\(\d+\)){3,}|\d+(?:(?: +|-)\d+){2,})$

您有一个演示here

解释:

^    # begin of line
    [+]?  # optinally start by +
    (?:   # group of possible options
        \d+ |         # first option: all numbers
        (?:\(\d+\)){3,} |    # second option: group of numbers withn parenthesis (min=3)
        \d+(?:(?: +|-)\d+){2,}  # third option: group of numbers separated by spaces or dash (min=3)
    )     # end of group of options
$    # end of line
相关问题