Which regular expression will match current international phone numbers?

I need to determine if the phone number is valid before trying to dial it. A phone can call anywhere in the world.

Which regular expression will match current international phone numbers?

+74
regex telephony ivr
Jan 21 '10 at 23:48
source share
19 answers
\+(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}$ 

The correct format for matching a common international phone number. I have replaced the US local telephone line access code 011 with the standard international access code identifier β€œ+”, which makes it mandatory. I also changed the minimum for the national number to at least one digit.

Please note: if you enter numbers in this format into your mobile phone address book, you can successfully call the number in your address book no matter where you travel. For landlines, replace the plus sign with the international access code for the country from which you are dialing.

Please note that this does NOT take into account national tariff plan rules - in particular, it allows the use of zeros and ones in places where national tariff plans do not allow, and also allows the number of lengths to exceed the national tariff plan for some countries (for example, USA )

+59
Aug 6 '11 at 15:38
source share

All country codes are defined by ITU. The following regular expression is based on ITU-T E.164 and the Appendix to ITU Operational Bulletin No. 930 - 15.IV.2009 . It contains all country codes and country codes reserved for future use. Although it can be shortened a bit, I decided to include each code myself.

This is for calls originating from the USA. For other countries, replace the international access code (011 at the beginning of the regular expression) with anything that suits the country ’s dialing plan .

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

 [0-9]{0,14}$ 

a end to regex.

Most importantly, this regular expression does not mean that the number is valid - each country determines its own internal numbering plan. This 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} $

+59
Jan 21 '10 at 23:49
source share

This is another optimization.

 \+(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 the use of valid international prefixes
(ii) followed by 9 or 10 digits, with any type or arrangement of delimiters (except for 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

+26
Aug 03 '13 at 5:29
source share

You can use the libphonenumber library 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(); } 
+14
Dec 03 '13 at 11:20
source share

Here is the "optimized" version of your regular expression:

 ^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 \d with [0-9] if your regex syntax does not support \d .

+10
Jan 22 '10 at 1:23
source share

I use this one:

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

Advantages: recognizes + or 011 beginnings, allows as long as necessary, and processes many extension agreements. (#, X, ext, extension)

+6
Oct 25 '13 at 14:17
source share

This will work for international numbers;

FROM#:

 @"^((\+\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}$/ 
+5
02 Oct '13 at 9:06 on
source share

For iOS SWIFT I found this useful

 let phoneRegEx = "^((\\+)|(00)|(\\*)|())[0-9]{3,14}((\\#)|())$" 
+5
Nov 25 '14 at 13:01
source share

Obviously, there are many ways to do this, as evidenced by all the various answers given so far, but I will drop my $ 0.02 here and provide the regex below, which is slightly shorter than almost all of the above, but more thorough than most. It also has a nice side effect, leaving a country code of $ 1 and a local number of $ 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 +) $

+2
Nov 19 '15 at 23:39
source share

A simple version for European numbers, which corresponds to numbers such as 0034617393211, but also long as 004401484172842.

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

Hope this helps: Β·)

+1
Nov 11 '15 at 1:16
source share
 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(); } 
+1
Oct 31 '16 at 17:23
source share

The international numbering plan is based on the ITU E.164 numbering plan . I assume the starting point of your regex.

I will update this if I manage to create a regular expression based on ITU E.164 numbering.

0
Jan 22 2018-10-10T00: 00Z
source share

This expression expression works for phones in India, Canada, Europe, New Zealand, Australia, the United States of America, as well as their country codes:

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

0
Jun 07 '16 at 9:42 on
source share

This works for me, without the prefix 00, 001, 0011, etc.

 /^\+*(\d{3})*[0-9,\-]{8,}/ 
0
Mar 25 '17 at 5:15
source share

Here is a regular expression for the following most common phone number scenarios. Although this is a US perspective for area codes, it works for international scenarios.

  • The actual number should be 10 digits.
  • For a US number code, the number may be surrounded by parentheses ().
  • The country code can contain from 1 to 3 digits. Optional may be preceded by a + sign.
  • There may be dashes, spaces, periods, or spaces between the country code, area code, and the rest of the number.
  • A valid phone number cannot be 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 

Additional examples and explanations - https://regex101.com/r/hTH8Ct/2/

0
Jun 25 '17 at 18:28
source share

I used this below:

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

Format + CCC.NNNNNNNNNNxXEEEE or 00CCC.NNNNNNNNNNXEEEE

The phone number must begin with "+" or "00" for an international call. where C is the country code with 1-3 digits,

N - up to 14 digits,

and E is an extension (optional).

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

0
Aug 18 '17 at 10:22 on
source share

Even though RegExp doesn't actually use RegExp to do the job - or maybe because of this - it looks like a nice solution for me: https://intl-tel-input.com/node_modules/intl- tel-input / examples / gen / is-valid-number.html

0
Oct 14 '17 at 16:40
source share

Changed regex @Eric - Added a list of all country codes (obtained from xxxdepy @Github , I hope you find it useful:

 /(\+|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}$/ 
0
Dec 23 '17 at 3:34 on
source share

Try this, I don't know if there is any phone number longer than 12:

 ^(00|\+){1}\d{12}$ 
-one
Sep 25 '16 at 15:24
source share



All Articles