Regular expression matching E.164 formatted phone numbers

后端 未结 7 1758
栀梦
栀梦 2020-12-23 16:14

I need to add a regular expression that matches all possible valid E.164 formatted phone numbers.

This regex works fine for for North American phone numbers, but I

7条回答
  •  余生分开走
    2020-12-23 16:46

    Well, I used the accepted answer but it failed for many cases:

    For inputs like:

    • Where numbers did not start with "+".
    • Where number count was less than 9.

    the regex failed.

    I finally used

    ^\+(?:[0-9]?){6,14}[0-9]$
    

    This worked like charm!

提交回复
热议问题