Regular expression matching E.164 formatted phone numbers

后端 未结 7 1743
栀梦
栀梦 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:38

    The accepted answer doesn't work with numbers without '+' sign. And I did a little math following the Wikipedia metrics, Country Code : 1 to 3 digits,
    maximum : 15, Actual Phone Number : 12 (upon 15-3) to 14 (15-1) digits

    The minimum in this regard is 10. For instance, the dummy US number "+14155552671" is the bare minimum. Breaking it down, +1 is US Country Code and the rest is all 'Area Code' + 'Subscriber Number' which is going to be 10. I couldn't find, in my research, a number less than 7 digits (Sweden) and is valid.

    So the regex I had to come up with that works along with '+' sign along with the digits which much reside between 10~15 is as follows:

    ^\++?[1-9][0-9]\d{6,14}$

    And this works well. You can check it out on Regex101.

提交回复
热议问题