177

I need to determine whether a phone number is valid before attempting to dial it. The phone call can go anywhere in the world.

What regular expression will match valid international phone numbers?

Abtin Forouzandeh
  • 5,635
  • 4
  • 25
  • 28
  • How does any regex handle errors like out of service numbers? Just try calling and handle invalid-number as you would other errors. –  Jan 21 '10 at 23:58
  • 5
    While you are correct that the regex cannot determine this, each outbound attempt consumes time and resources. Doing a quick sanity check on the number ensures that an obviously bogus call does not block a valuable channel. – Abtin Forouzandeh Jan 22 '10 at 00:01
  • 3
    LOL @ paxdiablo.... I guess 1-800-CALL-HELP will pass your RegExp test...lol – Buhake Sindi Jan 22 '10 at 00:31
  • 3
    Something that is not clear in this question is if the numbers have to be valid if called from the US or from any country in the world, because most of the solutions below do no validate some valid numbers (such as 0030 210 12312312 - a valid Greek number called from any EU country) – Xeroxoid Aug 11 '15 at 15:27
  • @Xeroxoid the question says "international phone number" in both the title and body. An international phone number is one with a `+` where the exit code needs to be. That exit code is indeed `00` in all EU countries (and the majority of countries elsewhere), but that still makes it the example you give an area-specific number (albeit one that works in a lot of specific areas), not an international one. – Jon Hanna Aug 12 '15 at 11:05
  • 2
    @JonHanna I agree to a point, but on the other hand, from the UX perspective don't you think that if a user inputs a 00XX...X number, the test should pass? There are cases where users (i.e. older people) don't even know what the + is and how to type it in on a numeric/phone keypad. Also I could still argue that 00XXX is a valid international number (i.e. in a user's context) where instead of the +, the exit code was used. – Xeroxoid Aug 13 '15 at 00:30
  • @Xeroxoid from a UI perspective, if you need an international phone number and the user enters a non-international phone number from which you can deduce the international phone number, then you should accept the number they entered, and turn it into the international phone number. That way you're reducing errors by dependably turning one form of input into another, rather than increasing errors by accepting invalid data. And how can something be international "in a user's context"? Being international means it works regardless of the geographical context ipso facto. – Jon Hanna Aug 13 '15 at 08:58

24 Answers24

136
\+(9[976]\d|8[987530]\d|6[987]\d|5[90]\d|42\d|3[875]\d|
2[98654321]\d|9[8543210]|8[6421]|6[6543210]|5[87654321]|
4[987654310]|3[9643210]|2[70]|7|1)\d{1,14}$

Is the correct format for matching a generic international phone number. I replaced the US land line centric international access code 011 with the standard international access code identifier of '+', making it mandatory. I also changed the minimum for the national number to at least one digit.

Note that if you enter numbers in this format into your mobile phone address book, you may successfully call any number in your address book no matter where you travel. For land lines, replace the plus with the international access code for the country you are dialing from.

Note that this DOES NOT take into account national number plan rules - specifically, it allows zeros and ones in locations that national number plans may not allow and also allows number lengths greater than the national number plan for some countries (e.g., the US).

Eric
  • 1,440
  • 1
  • 10
  • 3
  • 7
    Seems sensible to me. I'm going to use this one – Robert Johnstone Sep 06 '11 at 10:14
  • 34
    This is not valid. European phone numbers can start with a double 0 without a + in the beginning. Thus a phone number such as: +44 8984 1234 (UK) is also perfectly valid if written 0044 8984 1234 which this regexp (and on other answers as well) does not support. – Xeroxoid Aug 11 '15 at 15:29
  • @Eric so what DOES take into account national number plan rules?I will start with Norway: \+47 [84][0-9]{7}\. GO! – Mr. Developerdude Nov 18 '15 at 10:23
  • May be you can write like this: `^(\+|00){0,2}(9[976]\d|8[987530]\d|6[987]\d|5[90]\d|42\d|3[875]\d|2[98654321]\d|9[8543210]|8[6421]|6[6543210]|5[87654321]|4[987654310]|3[9643210]|2[70]|7|1)\d{1,14}$` – Ashwin Parmar Feb 28 '18 at 09:04
  • 10
    Combined with @fezfox's improvements(?) and length optimized: `^\+((?:9[679]|8[035789]|6[789]|5[90]|42|3[578]|2[1-689])|9[0-58]|8[1246]|6[0-6]|5[1-8]|4[013-9]|3[0-469]|2[70]|7|1)(?:\W*\d){0,13}\d$` – SamWhan Mar 05 '18 at 11:16
  • Sorry to revive an old old post however it may be worth noting for current readers that UK Company numbers, such as '0117 123 4567', are not deemed as valid by these Regex patterns. – J. Scull Oct 22 '19 at 10:56
  • @J.Scull did you read all the comments on this answer? You basically duplicated what Xeroxoid said. – rory.ap Oct 22 '19 at 13:31
  • @rory.ap It was reply to the more recent in the chain of comments, the latter of the provided Regex expressions does infact handle what Xeroxoid had mentioned, however it does not account for the business numbers as I mentioned, which if you read are still two different formats. – J. Scull Oct 23 '19 at 07:19
  • 4
    +1. From the UX point of view, yeah it might make sense to allow `00` in front. From development and maintenance point of view, I'd say it's perfectly fine to enforce all numbers to start with `+` or even replace `00` with a `+` each time you get it - especially given that most people are aware of the `+` format (which most international phone input fields require anyway). Plus it's a one-liner fix, and way more readable. This approach would also ensure that all phone numbers are in the same format, and makes your validation much less error-prone, thus making the whole thing more maintainable. – milosmns Nov 03 '19 at 12:04
  • 3
    And also, in the "old" days of pre-EDGE (plain GSM) SMS, using `00` would not send the message correctly, whereas starting with a `+` would always work internationally. We can go crazy and make it super complex, but sometimes it's possible/worth dropping a few constraints to make our lives easier :) – milosmns Nov 03 '19 at 12:07
  • Is there a reason @SamWhan's solution couldn't start with `^(\+|00)` and handle that case? – davemyron Jul 31 '20 at 23:21
  • 3
    @milosmns Yes, it is perfectly fine to enforce all numbers to start with a +, there are UX friendly ways to do this. For example let them select their country from a dropdown and show that you prefix the phone number with +44 (in case of UK). Now it is clear that you have to enter the number starting with + – Danagon Jul 27 '21 at 12:41
73

All country codes are defined by the ITU. The following regex is based on ITU-T E.164 and Annex to ITU Operational Bulletin No. 930 – 15.IV.2009. It contains all current country codes and codes reserved for future use. While it could be shortened a bit, I decided to include each code independently.

This is for calls originating from the USA. For other countries, replace the international access code (the 011 at the beginning of the regex) with whatever is appropriate for that country's dialing plan.

Also, note that ITU E.164 defines the maximum length of a full international telephone number to 15 digits. This means a three digit country code results in up to 12 additional digits, and a 1 digit country code could contain up to 14 additional digits. Hence the

[0-9]{0,14}$

a the end of the regex.

Most importantly, this regex does not mean the number is valid - each country defines its own internal numbering plan. This only ensures that the country code is valid.

^011(999|998|997|996|995|994|993|992|991| 990|979|978|977|976|975|974|973|972|971|970| 969|968|967|966|965|964|963|962|961|960|899| 898|897|896|895|894|893|892|891|890|889|888| 887|886|885|884|883|882|881|880|879|878|877| 876|875|874|873|872|871|870|859|858|857|856| 855|854|853|852|851|850|839|838|837|836|835| 834|833|832|831|830|809|808|807|806|805|804| 803|802|801|800|699|698|697|696|695|694|693| 692|691|690|689|688|687|686|685|684|683|682| 681|680|679|678|677|676|675|674|673|672|671| 670|599|598|597|596|595|594|593|592|591|590| 509|508|507|506|505|504|503|502|501|500|429| 428|427|426|425|424|423|422|421|420|389|388| 387|386|385|384|383|382|381|380|379|378|377| 376|375|374|373|372|371|370|359|358|357|356| 355|354|353|352|351|350|299|298|297|296|295| 294|293|292|291|290|289|288|287|286|285|284| 283|282|281|280|269|268|267|266|265|264|263| 262|261|260|259|258|257|256|255|254|253|252| 251|250|249|248|247|246|245|244|243|242|241| 240|239|238|237|236|235|234|233|232|231|230| 229|228|227|226|225|224|223|222|221|220|219| 218|217|216|215|214|213|212|211|210|98|95|94| 93|92|91|90|86|84|82|81|66|65|64|63|62|61|60| 58|57|56|55|54|53|52|51|49|48|47|46|45|44|43| 41|40|39|36|34|33|32|31|30|27|20|7|1)[0-9]{0, 14}$

Abtin Forouzandeh
  • 5,635
  • 4
  • 25
  • 28
  • 17
    Almost had it right... "011" is not part of an international code. It's just what people in the US need to dial in order to place an international call. That prefix will change depending on where you dial from... So that prefix is NOT part of the number. – Gabriel Magana Jan 21 '10 at 23:51
  • 4
    @gmagana - I mention that in my answer (paragraph 2) – Abtin Forouzandeh Jan 21 '10 at 23:53
  • 2
    My point is that it's not part of the phone number. That's like saying the "1" US national long distance dialing prefix is part of the phone number. – Gabriel Magana Jan 21 '10 at 23:55
  • 2
    @gmagana - while you are right that it is not part of the phone number, it is technically required to make the call. – Abtin Forouzandeh Jan 22 '10 at 00:06
  • @Abtin: You asked this question just to tell us about your already existing solution? –  Jan 22 '10 at 00:29
  • 3
    @Roger Pate: I spent a bit of time figuring this out and I hope it will be useful to others. I also hoped that someone else might have a better solution (which is why I haven't marked my own answer as accepted). – Abtin Forouzandeh Jan 22 '10 at 00:43
  • I'm not going to downvote, but... couldn't you just check yourself: first three digits 011, next three in a lookup table, and rest of the characters digits? Why bother with regex? And why does it say `{0,14}`? Is `011` really a valid number? Surely most countries have enough phone lines to warrant a digit or two... – Cascabel Jan 25 '11 at 22:59
  • Say you wanted to get the Country Code using this regex. Is there ever a case where the country code will get "confused" with the actual phone number? Say for instance there are 2 countries with codes 231 and 23. In this case a number in country 23 starting with 1 will get confused with country 231. Is E164 specifically designed to allocate country codes so this will not happen? – Josh Nankin Feb 02 '12 at 21:03
  • 2
    The comment for insanity has more votes than the answer. Insanity! – Jimi Sep 16 '15 at 11:42
  • publication has been removed or moved. – David Fisher Jul 26 '20 at 15:12
  • [0-9]{0,14}$ validates the last 14 digits of a number longer than 14 digits. I don't think that is intended behaviour. – Drishti Jain Jul 21 '22 at 08:06
41

This is a further optimisation.

\+(9[976]\d|8[987530]\d|6[987]\d|5[90]\d|42\d|3[875]\d|
2[98654321]\d|9[8543210]|8[6421]|6[6543210]|5[87654321]|
4[987654310]|3[9643210]|2[70]|7|1)
\W*\d\W*\d\W*\d\W*\d\W*\d\W*\d\W*\d\W*\d\W*(\d{1,2})$

(i) allows for valid international prefixes
(ii) followed by 9 or 10 digits, with any type or placing of delimeters (except between the last two digits)

This will match:

+1-234-567-8901  
+61-234-567-89-01  
+46-234 5678901  
+1 (234) 56 89 901  
+1 (234) 56-89 901  
+46.234.567.8901  
+1/234/567/8901  
InSync
  • 4,851
  • 4
  • 8
  • 30
fezfox
  • 967
  • 9
  • 14
  • I know this is an old answer, but is there any option to make the 1 optional for American numbers? – Adam Fratino Dec 01 '16 at 18:23
  • What you want to do is (i) make the "+" optional and (ii) the international code optional. So place "?" after the + and after the first close bracket. – fezfox Dec 04 '16 at 03:31
  • @ManosPasgiannis well yes, as specified "followed by 9 or 10 digits". It would appear in cyprus you use 8, so just adjust the last sequence by removing once instance of \d\W* and make the last expression (\d{1,3}) – fezfox Dec 04 '16 at 03:35
31

You can use the library libphonenumber from Google.

PhoneNumberUtil phoneNumberUtil = PhoneNumberUtil.getInstance();
String decodedNumber = null;
PhoneNumber number;
    try {
        number = phoneNumberUtil.parse(encodedHeader, null);
        decodedNumber = phoneNumberUtil.format(number, PhoneNumberFormat.E164);
    } catch (NumberParseException e) {
        e.printStackTrace();
    }
Paulo Fidalgo
  • 21,709
  • 7
  • 99
  • 115
  • 3
    It could be a good solution but just to check phone numbers, before using this library, you have to import a huge amount of js...because libphonenumber.js needs [closure library](https://developers.google.com/closure/library/docs/gettingstarted)... it's not a light solution :/ – J.BizMai Sep 19 '17 at 14:18
  • @J.BizMai not exactly... closure library code is designed to be compiled using Closure Compiler which does dead code elimination. With advanced optimizations enabled the compiled lib would probably be very light and performant. – Pocketsand Feb 22 '21 at 11:35
  • Thanks for contributing this here. Just wanted to mention the Python port if anyone is interested. It's more of a "light solution" if @J.BizMai's comments resonate with you: https://github.com/daviddrysdale/python-phonenumbers – Joel Mellon Feb 16 '23 at 21:11
31

No criticism regarding those great answers I just want to present the simple solution I use for our admin content creators:

^(\+|00)[1-9][0-9 \-\(\)\.]{7,32}$

Force start with a plus or two zeros and use at least a little bit of numbers. White space, brackets, minus and point are optional, no other characters allowed.

You can safely remove all non-numbers (except for the +) and use this in a tel: input. Numbers will have a common form of representation and I do not have to worry about being to restrictive.

Blackbam
  • 17,496
  • 26
  • 97
  • 150
28

Modified @Eric's regular expression - added a list of all country codes (got them from xxxdepy @ Github. I hope you will find it helpful:

/(\+|00)(297|93|244|1264|358|355|376|971|54|374|1684|1268|61|43|994|257|32|229|226|880|359|973|1242|387|590|375|501|1441|591|55|1246|673|975|267|236|1|61|41|56|86|225|237|243|242|682|57|269|238|506|53|5999|61|1345|357|420|49|253|1767|45|1809|1829|1849|213|593|20|291|212|34|372|251|358|679|500|33|298|691|241|44|995|44|233|350|224|590|220|245|240|30|1473|299|502|594|1671|592|852|504|385|509|36|62|44|91|246|353|98|964|354|972|39|1876|44|962|81|76|77|254|996|855|686|1869|82|383|965|856|961|231|218|1758|423|94|266|370|352|371|853|590|212|377|373|261|960|52|692|389|223|356|95|382|976|1670|258|222|1664|596|230|265|60|262|264|687|227|672|234|505|683|31|47|977|674|64|968|92|507|64|51|63|680|675|48|1787|1939|850|351|595|970|689|974|262|40|7|250|966|249|221|65|500|4779|677|232|503|378|252|508|381|211|239|597|421|386|46|268|1721|248|963|1649|235|228|66|992|690|993|670|676|1868|216|90|688|886|255|256|380|598|1|998|3906698|379|1784|58|1284|1340|84|678|681|685|967|27|260|263)(9[976]\d|8[987530]\d|6[987]\d|5[90]\d|42\d|3[875]\d|2[98654321]\d|9[8543210]|8[6421]|6[6543210]|5[87654321]|4[987654310]|3[9643210]|2[70]|7|1)\d{4,20}$/
Dev
  • 677
  • 1
  • 8
  • 19
16

I use this one:

/([0-9\s\-]{7,})(?:\s*(?:#|x\.?|ext\.?|extension)\s*(\d+))?$/

Advantages: recognizes + or 011 beginnings, lets it be as long as needed, and handles many extension conventions. (#,x,ext,extension)

TOBlender
  • 1,053
  • 11
  • 17
13

This will work for international numbers;

C#:

@"^((\+\d{1,3}(-| )?\(?\d\)?(-| )?\d{1,5})|(\(?\d{2,6}\)?))(-| )?(\d{3,4})(-| )?(\d{4})(( x| ext)\d{1,5}){0,1}$"

JS:

/^((\+\d{1,3}(-| )?\(?\d\)?(-| )?\d{1,5})|(\(?\d{2,6}\)?))(-| )?(\d{3,4})(-| )?(\d{4})(( x| ext)\d{1,5}){0,1}$/
JRG-Developer
  • 12,454
  • 8
  • 55
  • 81
MADol
  • 139
  • 1
  • 3
9

Here's an "optimized" version of your regex:

^011(9[976]\d|8[987530]\d|6[987]\d|5[90]\d|42\d|3[875]\d|
2[98654321]\d|9[8543210]|8[6421]|6[6543210]|5[87654321]|
4[987654310]|3[9643210]|2[70]|7|1)\d{0,14}$

You can replace the \ds with [0-9] if your regex syntax doesn't support \d.

Laurence Gonsalves
  • 137,896
  • 35
  • 246
  • 299
9

For iOS SWIFT I found this helpful,

let phoneRegEx = "^((\\+)|(00)|(\\*)|())[0-9]{3,14}((\\#)|())$"
Mohammad Zaid Pathan
  • 16,304
  • 7
  • 99
  • 130
7

I only check for valid characters and allow up to 30 characters. Numbers that include an extension are also possible.

^[\+\(\s.\-\/\d\)]{5,30}$

Matches the following:

(0123) 123 456 1
555-555-5555
0049 1555 532-3455
123 456 7890
0761 12 34 56
+49 123 1-234-567-8901
+61-234-567-89-01
+46-234 5678901
+1 (234) 56 89 901
+1 (234) 56-89 901
+46.234.567.8901
+1/234/567/8901
Ben
  • 811
  • 12
  • 28
  • Thanks for this - many people want to enter their number differently, some with + some with 00, some with ext, so local, so this is perfect for loosely capturing them, – Kingsley Nov 17 '22 at 17:01
  • This is one of the best and simplest answers here. Depending on your use-case though, it may not be suitable, eg. it matches `1 )212) 366-1182` and things like a long US postal code: `12345-1234`. This may be OK for basic form validation, but definitely not for extraction of business info from a webpage, for example. Great answer regardless. – Joel Mellon Feb 16 '23 at 21:05
6

Here is a regex for the following most common phone number scenarios. Although this is tailored from a US perspective for area codes it works for international scenarios.

  1. The actual number should be 10 digits only.
  2. For US numbers area code may be surrounded with parentheses ().
  3. The country code can be 1 to 3 digits long. Optionally may be preceded by a + sign.
  4. There may be dashes, spaces, dots or no spaces between country code, area code and the rest of the number.
  5. A valid phone number cannot be all zeros.

    ^(?!\b(0)\1+\b)(\+?\d{1,3}[. -]?)?\(?\d{3}\)?([. -]?)\d{3}\3\d{4}$
    

Explanation:

    ^ - start of expression  
    (?!\b(0)\1+\b) - (?!)Negative Look ahead. \b - word boundary around a '0' character. \1 backtrack to previous capturing group (zero). Basically don't match all zeros.  
    (\+?\d{1,3}[. -]?)? - '\+?' plus sign before country code is optional.\d{1,3} - country code can be 1 to 3 digits long. '[. -]?' - spaces,dots and dashes are optional. The last question mark is to make country code optional.  
    \(?\d{3}\)? - '\)?' is to make parentheses optional. \d{3} - match 3 digit area code.  
    ([. -]?) - optional space, dash or dot
    $ - end of expression

More examples and explanation - https://regex101.com/r/hTH8Ct/2/

Appy
  • 601
  • 2
  • 7
  • 12
6

I have used this below:

^(\+|00)[0-9]{1,3}[0-9]{4,14}(?:x.+)?$

The format +CCC.NNNNNNNNNNxEEEE or 00CCC.NNNNNNNNNNxEEEE

Phone number must start with '+' or '00' for an international call. where C is the 1–3 digit country code,

N is up to 14 digits,

and E is the (optional) extension.

The leading plus sign and the dot following the country code are required. The literal “x” character is required only if an extension is provided.

Rousonur Jaman
  • 1,183
  • 14
  • 19
5

I made the regexp for european phone numbers, and it is specific against dial prefix vs length of number.

const PhoneEuropeRegExp = () => {
    // eu phones map https://en.wikipedia.org/wiki/Telephone_numbers_in_Europe
    const phonesMap = {
        "43": [4, 13],
        "32": [8, 10],
        "359": [7, 9],
        "385": [8, 9],
        "357": 8,
        "420": 9,
        "45": 8,
        "372": 7,
        "358": [5, 12],
        "33": 9,
        "350": 8,
        "49": [3, 12],
        "30": 10,
        "36": [8, 9],
        "354": [7, 9],
        "353": [7, 9],
        "39": [6, 12],
        "371": 8,
        "423": [7, 12],
        "370": 8,
        "352": 8,
        "356": 8,
        "31": 9,
        "47": [4, 12],
        "48": 9,
        "351": 9,
        "40": 9,
        "421": 9,
        "386": 8,
        "34": 9,
        "46": [6, 9],
    };
    const regExpBuilt = Object.keys(phonesMap)
        .reduce(function(prev, key) {
            const val = phonesMap[key];
            if (Array.isArray(val)) {
                prev.push("(\\+" + key + `[0-9]\{${val[0]},${val[1]}\})`);
            } else {
                prev.push("(\\+" + key + `[0-9]\{${val}\})`);
            }
            return prev;
        }, [])
        .join("|");
    return new RegExp(`^(${regExpBuilt})$`);
};

alert(PhoneEuropeRegExp().test("+420123456789"))
luky
  • 2,263
  • 3
  • 22
  • 40
4

It works pretty well with 00xx and +xx:

^(?:00|\+)(9[976]\d|8[987530]\d|6[987]\d|5[90]\d|42\d|3[875]\d|2[98654321]\d|9[8543210]|8[6421]|6[6543210]|5[87654321]|4[987654310]|3[9643210]|2[70]|7|1)\d{1,14}$
Hossein Kurd
  • 3,184
  • 3
  • 41
  • 71
3

There's obviously a multitude of ways to do this, as evidenced by all of the different answers given thus far, but I'll throw my $0.02 worth in here and provide the regex below, which is a bit more terse than nearly all of the above, but more thorough than most as well. It also has the nice side-effect of leaving the country code in $1 and the local number in $2.

^\+(?=\d{5,15}$)(1|2[078]|3[0-469]|4[013-9]|5[1-8]|6[0-6]|7|8[1-469]|9[0-58]|[2-9]..)(\d+)$

trekinaz
  • 31
  • 2
2

A simple version for european numbers, that matches numbers like 0034617393211 but also long ones as 004401484172842.

^0{2}[0-9]{11,}

Hope it helps :·)

Roc Boronat
  • 11,395
  • 5
  • 47
  • 59
2
public static boolean validateInternationalPhoneNumberFormat(String phone) {
    StringBuilder sb = new StringBuilder(200);

    // Country code
    sb.append("^(\\+{1}[\\d]{1,3})?");

    // Area code, with or without parentheses
    sb.append("([\\s])?(([\\(]{1}[\\d]{2,3}[\\)]{1}[\\s]?)|([\\d]{2,3}[\\s]?))?");

    // Phone number separator can be "-", "." or " "

    // Minimum of 5 digits (for fixed line phones in Solomon Islands)
    sb.append("\\d[\\-\\.\\s]?\\d[\\-\\.\\s]?\\d[\\-\\.\\s]?\\d[\\-\\.\\s]?\\d[\\-\\.\\s]?");

    // 4 more optional digits
    sb.append("\\d?[\\-\\.\\s]?\\d?[\\-\\.\\s]?\\d?[\\-\\.\\s]?\\d?$");

    return Pattern.compile(sb.toString()).matcher(phone).find();
}
Cássio
  • 329
  • 3
  • 11
  • 3
    While this code snippet may answer the question, it doesn't provide any context to explain how or why. Consider adding a sentence or two to explain your answer. – brandonscript Oct 31 '16 at 18:32
0

The international numbering plan is based on the ITU E.164 numbering plan. I guess that's the starting point to your regular expression.

I'll update this if I get around to create a regular expression based on the ITU E.164 numbering.

Buhake Sindi
  • 87,898
  • 29
  • 167
  • 228
0

This Regex Expression works for India, Canada, Europe, New Zealand, Australia, United States phone numbers, along with their country codes:

"^(\+(([0-9]){1,2})[-.])?((((([0-9]){2,3})[-.]){1,2}([0-9]{4,10}))|([0-9]{10}))$"

brodoll
  • 1,851
  • 5
  • 22
  • 25
0

This works for me, without 00, 001, 0011 etc prefix though:

/^\+*(\d{3})*[0-9,\-]{8,}/
redwud
  • 174
  • 3
  • 8
0

Try this, it works for me.

^(00|\+)[1-9]{1}([0-9][\s]*){9,16}$
AbdulAhmad Matin
  • 1,047
  • 1
  • 18
  • 27
0
^\+[1-9]\d{10,14}$

This will match "e164 phone numbers"

Fractal Mind
  • 405
  • 4
  • 10
0

Added for latest info in 2023

If you want to keep is as simple as possible, just inform your users to enter the + prefix and the full number, using digits only.

Then the regex is simple, your UI is simple, there is no confusion, no cleanup and ALL numbers can be entered and stored in the same format.

\+\d{7,15}
  1. Must start with +
  2. Can be followed by 7-15 digits.

Thanks to the international phone numbering plan (ITU-T E. 164), phone numbers cannot contain more than 15 digits. The shortest international phone numbers in use contain seven digits.

This would be perfect, for example, if you only needed to capture mobile numbers to send an OPT code or SMS.

But if you want to be more specific the EPP standard has fast become adopted, since most domain registration services use it.

In which case you need:

^\+[0-9]{1,3}\.[0-9]{4,14}(?:x.+)?$

EPP-style phone numbers use the format +CCC.NNNNNNNNNNxEEEE, where C is the 1–3 digit country code, N is up to 14 digits, and E is the (optional) extension. The leading plus sign and the dot following the country code are required. The literal “x” character is required only if an extension is provided.

Source: https://www.oreilly.com/library/view/regular-expressions-cookbook/9781449327453/ch04s03.html#:~:text=Thanks%20to%20the%20international%20phone,in%20use%20contain%20seven%20digits.

rmcsharry
  • 5,363
  • 6
  • 65
  • 108