246

I want to write a regular expression for a standard US type phone number that supports the following formats:

###-###-####
(###) ###-####
### ### ####
###.###.####

where # means any number. So far I came up with the following expressions

^[1-9]\d{2}-\d{3}-\d{4}
^\(\d{3}\)\s\d{3}-\d{4}
^[1-9]\d{2}\s\d{3}\s\d{4}
^[1-9]\d{2}\.\d{3}\.\d{4}

respectively. I am not quite sure if the last one is correct for the dotted check. I also want to know if there is any way I could write a single expression instead of the 4 different ones that cater to the different formats I mentioned. If so, I am not sure how do I do that. And also how do I modify the expression/expressions so that I can also include a condition to support the area code as optional component. Something like

+1 ### ### ####

where +1 is the area code and it is optional.

5
  • 6
    possible duplicate of stackoverflow.com/questions/123559/… the suggested answer is to strip every non-digit character. In this way, you simplify the validation Commented May 22, 2013 at 18:24
  • 1
    I know this was a while back, but I don't think US area codes can begin with 1. (123) 456-7890 would be invalid because of the leading 1.
    – bobanahalf
    Commented Jul 31, 2015 at 19:49
  • For a more complete correct answer see: stackoverflow.com/a/18626090/561710 Commented Sep 11, 2017 at 17:23
  • Parsing phone numbers is hard. Google released an open source lib for this. Help yourself, use libphonenumber (or a fork in your language)
    – aloisdg
    Commented Mar 30, 2018 at 15:05
  • 1
    If you are trying to do this, you are probably doing it wrong. Phone numbers are of varying lengths, include different country codes and in general are wierder than you think. Python and Java both have libraries that will parse phone numbers contextually and you should be using those kind of tools instead of trying to get a regex to do the job.
    – boatcoder
    Commented May 8, 2022 at 12:54

24 Answers 24

399
^(\+\d{1,2}\s)?\(?\d{3}\)?[\s.-]\d{3}[\s.-]\d{4}$

Matches the following

123-456-7890
(123) 456-7890
123 456 7890
123.456.7890
+91 (123) 456-7890

If you do not want a match on non-US numbers use

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

Update :
As noticed by user Simon Weaver below, if you are also interested in matching on unformatted numbers just make the separator character class optional as [\s.-]?

^(\+\d{1,2}\s?)?\(?\d{3}\)?[\s.-]?\d{3}[\s.-]?\d{4}$

https://regex101.com/r/j48BZs/2

20
  • 1
    Do you think that the question mark is not necessary in (?\d{3}) part of your very first line ? I think we do need one or more occurrence and not zero or one occurrence of a digit within the '(' and ')'
    – noobcoder
    Commented May 22, 2013 at 19:54
  • 3
    The ? there applies on parentheses (), not on the digits. The complete related regex is \(?\d{3}\)?. \d{3} specifies that there must be three digits between the () that are (made) optional (by ?). Commented May 22, 2013 at 20:07
  • 10
    note: this doesn't match 1234567890 which may or may not be a problem. for me it was - so I just added ? after each [\s.-] to make it optional Commented Aug 12, 2014 at 20:59
  • 1
    @Simon_Weaver Thank you for your inputs. I've added your observation to the answer. Commented Jan 12, 2015 at 15:17
  • 3
    If you want one that avoids the issue @BobRay mentioned, use ^(\+\d{1,2}\s)?((\(\d{3}\))|(\d{3}))[\s.-]\d{3}[\s.-]\d{4}$. (I basically just duplicated the segment of the RegEx that covers the area code and allowed one variant with parens and one without) Commented Sep 17, 2018 at 11:35
245

There are many variations possible for this problem. Here is a regular expression similar to an answer I previously placed on SO.

^\s*(?:\+?(\d{1,3}))?[-. (]*(\d{3})[-. )]*(\d{3})[-. ]*(\d{4})(?: *x(\d+))?\s*$

It would match the following examples and much more:

18005551234
1 800 555 1234
+1 800 555-1234
+86 800 555 1234
1-800-555-1234
1 (800) 555-1234
(800)555-1234
(800) 555-1234
(800)5551234
800-555-1234
800.555.1234
800 555 1234x5678
8005551234 x5678
1    800    555-1234
1----800----555-1234

Regardless of the way the phone number is entered, the capture groups can be used to breakdown the phone number so you can process it in your code.

  • Group1: Country Code (ex: 1 or 86)
  • Group2: Area Code (ex: 800)
  • Group3: Exchange (ex: 555)
  • Group4: Subscriber Number (ex: 1234)
  • Group5: Extension (ex: 5678)

Here is a breakdown of the expression if you're interested:

^\s*                #Line start, match any whitespaces at the beginning if any.
(?:\+?(\d{1,3}))?   #GROUP 1: The country code. Optional.
[-. (]*             #Allow certain non numeric characters that may appear between the Country Code and the Area Code.
(\d{3})             #GROUP 2: The Area Code. Required.
[-. )]*             #Allow certain non numeric characters that may appear between the Area Code and the Exchange number.
(\d{3})             #GROUP 3: The Exchange number. Required.
[-. ]*              #Allow certain non numeric characters that may appear between the Exchange number and the Subscriber number.
(\d{4})             #Group 4: The Subscriber Number. Required.
(?: *x(\d+))?       #Group 5: The Extension number. Optional.
\s*$                #Match any ending whitespaces if any and the end of string.

To make the Area Code optional, just add a question mark after the (\d{3}) for the area code.

12
  • 11
    best answer IMHO. For my purpose, the \s at the beginning and end are not needed, because I'm using for validation, and the field is trimmed already.
    – Daniel
    Commented May 26, 2015 at 20:31
  • 3
    By far the best answer and most complete. I also really appreciate the regex breakdown. Commented May 25, 2017 at 13:05
  • @Kondal I'm curious about the input you're using to make it fail. It seems to work fine for me with a 0 for the country code. Commented Nov 22, 2017 at 12:41
  • <input type="text" name="phone_no" class="form-control" ng-pattern="^\s*(?:\+?(\d{1,3}))?[-. (]*(\d{3})[-. )]*(\d{3})[-. ]*(\d{4})(?: *x(\d+))?\s*$" only-numbers ng-maxlength="10" />
    – Kondal
    Commented Nov 22, 2017 at 13:04
  • @Kondal Sorry. I meant the text you are trying to match that is failing with this regex. Commented Nov 23, 2017 at 12:32
50

^(\+\d{1,2}\s?)?1?\-?\.?\s?\(?\d{3}\)?[\s.-]?\d{3}[\s.-]?\d{4}$

Matches these phone numbers:

1-718-444-1122
718-444-1122
(718)-444-1122
17184441122
7184441122
718.444.1122
1718.444.1122
1-123-456-7890
1 123-456-7890
1 (123) 456-7890
1 123 456 7890
1.123.456.7890
+91 (123) 456-7890
18005551234
1 800 555 1234
+1 800 555-1234
+86 800 555 1234
1-800-555-1234
1 (800) 555-1234
(800)555-1234
(800) 555-1234
(800)5551234
800-555-1234
800.555.1234
18001234567
1 800 123 4567
1-800-123-4567
+18001234567
+1 800 123 4567
+1 (800) 123 4567
1(800)1234567
+1800 1234567
1.8001234567
1.800.123.4567
+1 (800) 123-4567
18001234567
1 800 123 4567
+1 800 123-4567
+86 800 123 4567
1-800-123-4567
1 (800) 123-4567
(800)123-4567
(800) 123-4567
(800)1234567
800-123-4567
800.123.4567
1231231231
123-1231231
123123-1231
123-123 1231
123 123-1231
123-123-1231
(123)123-1231
(123)123 1231
(123) 123-1231
(123) 123 1231
+99 1234567890
+991234567890
(555) 444-6789
555-444-6789
555.444.6789
555 444 6789
18005551234
1 800 555 1234
+1 800 555-1234
+86 800 555 1234
1-800-555-1234
1.800.555.1234
+1.800.555.1234
1 (800) 555-1234
(800)555-1234
(800) 555-1234
(800)5551234
800-555-1234
800.555.1234
(003) 555-1212
(103) 555-1212
(911) 555-1212
18005551234
1 800 555 1234
+86 800-555-1234
1 (800) 555-1234

See regex101.com

3
  • With a slight modification, this also supports local phone numbers without the area code: ((\+\d{1,2}\s?)?1?\-?\.?\s?\(?\d{3}\)?[\s.-]?)?\d{3}[\s.-]?\d{4}
    – TayTay
    Commented Dec 9, 2021 at 13:32
  • this is the best; I came back years later to find this
    – MoKi
    Commented Apr 16, 2023 at 16:37
  • good, but it doesn't handle (123) - 622 - 1000 check this regex demo. Commented Jan 28 at 17:55
25

Regex pattern to validate a regular 10 digit phone number plus optional international code (1 to 3 digits) and optional extension number (any number of digits):

/(\+\d{1,3}\s?)?((\(\d{3}\)\s?)|(\d{3})(\s|-?))(\d{3}(\s|-?))(\d{4})(\s?(([E|e]xt[:|.|]?)|x|X)(\s?\d+))?/g

Demo: https://www.regextester.com/103299

Valid entries:

/* Full number */
+999 (999) 999-9999 Ext. 99999

/* Regular local phone number (XXX) XXX-XXXX */
1231231231
123-1231231
123123-1231
123-123 1231
123 123-1231
123-123-1231
(123)123-1231
(123)123 1231
(123) 123-1231
(123) 123 1231

/* International codes +XXX (XXX) XXX-XXXX */
+99 1234567890
+991234567890

/* Extensions (XXX) XXX-XXXX Ext. XXX... */
1234567890 Ext 1123123
1234567890Ext 1123123
1234567890 Ext1123123
1234567890Ext1123123

1234567890 Ext: 1123123
1234567890Ext: 1123123
1234567890 Ext:1123123
1234567890Ext:1123123

1234567890 Ext. 1123123
1234567890Ext. 1123123
1234567890 Ext.1123123
1234567890Ext.1123123

1234567890 ext 1123123
1234567890ext 1123123
1234567890 ext1123123
1234567890ext1123123

1234567890 ext: 1123123
1234567890ext: 1123123
1234567890 ext:1123123
1234567890ext:1123123

1234567890 X 1123123
1234567890X1123123
1234567890X 1123123
1234567890 X1123123
1234567890 x 1123123
1234567890x1123123
1234567890 x1123123
1234567890x 1123123
10

Here's a fairly compact one I created.

Search: \+?1?\s*\(?-*\.*(\d{3})\)?\.*-*\s*(\d{3})\.*-*\s*(\d{4})$

Replace: +1 \($1\) $2-$3

Tested against the following use cases.

18001234567
1 800 123 4567
1-800-123-4567
+18001234567
+1 800 123 4567
+1 (800) 123 4567
1(800)1234567
+1800 1234567
1.8001234567
1.800.123.4567
1--800--123--4567
+1 (800) 123-4567
1
  • 1
    This matches stuff like (800 444-4444
    – Jake
    Commented Dec 11, 2015 at 4:20
6

Adding up an example using above mentioned solutions on jsfiddle. I have modified the code a bit as per my clients requirement. Hope this also helps someone.

/^\s*(?:\+?(\d{1,3}))?[- (]*(\d{3})[- )]*(\d{3})[- ]*(\d{4})(?: *[x/#]{1}(\d+))?\s*$/

See Example Here

6

Phone number regex that I use: /^[+]?(\d{1,2})?[\s.-]?\(?\d{3}\)?[\s.-]?\d{3}[\s.-]?\d{4}$/

Covers:

  • 18001234567
  • 1 800 123 4567
  • +1 800 123-4567
  • +86 800 123 4567
  • 1-800-123-4567
  • 1 (800) 123-4567
  • (800)123-4567
  • (800) 123-4567
  • (800)1234567
  • 800-123-4567
  • 800.123.4567
1
  • your regex doesn't match if there is a whitespace, here is the demo. Commented Jan 28 at 17:58
5

Starting with @Ravi's answer, I also applied some validation rules for the NPA (Area) Code.

In particular:

  • It should start with a 2 (or higher)
  • It cannot have "11" as the second and third digits (N11).

There are a couple other restrictions, including reserved blocks (N9X, 37X, 96X) and 555, but I left those out, particularly because the reserved blocks may see future use, and 555 is useful for testing.

This is what I came up with:

^((\+\d{1,2}|1)[\s.-]?)?\(?[2-9](?!11)\d{2}\)?[\s.-]?\d{3}[\s.-]?\d{4}$

Alternately, if you also want to match blank values (if the field isn't required), you can use:

(^((\+\d{1,2}|1)[\s.-]?)?\(?[2-9](?!11)\d{2}\)?[\s.-]?\d{3}[\s.-]?\d{4}$|^$)

My test cases for valid numbers (many from @Francis' answer) are:

18005551234
1 800 555 1234
+1 800 555-1234
+86 800 555 1234
1-800-555-1234
1.800.555.1234
+1.800.555.1234
1 (800) 555-1234
(800)555-1234
(800) 555-1234
(800)5551234
800-555-1234
800.555.1234

My invalid test cases include:

(003) 555-1212     // Area code starts with 0
(103) 555-1212     // Area code starts with 1
(911) 555-1212     // Area code ends with 11
180055512345       // Too many digits
1 800 5555 1234    // Prefix code too long
+1 800 555x1234    // Invalid delimiter
+867 800 555 1234  // Country code too long
1-800-555-1234p    // Invalid character
1 (800)  555-1234  // Too many spaces
800x555x1234       // Invalid delimiter
86 800 555 1212    // Non-NA country code doesn't have +

My regular expression does not include grouping to extract the digit groups, but it can be modified to include those.

0
5

I find this regular expression most useful for me for 10 digit contact number :

^(?:(?:\+|0{0,2})91(\s*[\-]\s*)?|[0]?)?[789]\d{9}$

Reference: https://regex101.com/r/QeQewP/1

Explanation:

enter image description here

5
  • Did you use a tool to generate that explanation? Do share! Thanks
    – unnknown
    Commented Jan 3, 2019 at 20:38
  • 2
    @unnknown Looks like a screenshot from an online regex checker, such as regex101.com. Note that SO guidelines state that all text, code, data, and error messages must be input in text form, not images, because text in images can be difficult to read, particularly on mobile devices, and incurs greater bandwidth. Also text cannot be copy-pasted. In this case, the colors might add something, not sure. Know that generally, "Answers" should include a textual explanation. Amitesh: it would be useful to include a link to this site, with your regex already populated for visitors to experiment with. Commented Apr 13, 2020 at 6:36
  • @unnknown here is a link that produces an image similar to the one in this post. Amitesh's regex string has been already pasted in. You can enter phone numbers to test its results: regex101.com/r/QeQewP/1 Commented Apr 13, 2020 at 6:40
  • how to use this? Commented Feb 7, 2022 at 10:38
  • @RohanDevaki Regex is a powerful tool used to validate, manipulate, and extract data from text. Different languages have different inbuilt methods to use it. Which language do you want to use? meanwhile, the following article provides an example for using regular expressions in 10 different languages. I would recommend to give it read blog.teamtreehouse.com/regular-expressions-10-languages Commented Feb 9, 2022 at 6:33
4

try this for Pakistani users .Here's a fairly compact one I created.

((\+92)|0)[.\- ]?[0-9][.\- ]?[0-9][.\- ]?[0-9]

Tested against the following use cases.

+92 -345 -123 -4567
+92 333 123 4567
+92 300 123 4567
+92 321 123 -4567
+92 345 - 540 - 5883
1
  • Hello Sajjid.If i want to add 03041234567. What would be Regular expression.
    – Anees
    Commented Dec 30, 2020 at 14:19
3

Perhaps the easiest one compare to several others.

\(?\d+\)?[-.\s]?\d+[-.\s]?\d+

It matches the following:

(555) 444-6789

555-444-6789

555.444.6789

555 444 6789

1
  • Perfect one... Thanks (y) Commented Sep 11, 2018 at 8:45
2

The expressions for 1, 3 and 4 are quite similar, so you can use:

^([1-9]\d{2})([- .])(\d{3})$2(\d{4})$

Note that, depending on the language and brand of regexes used, you might need to put \2 instead of $2 or such matching might not be supported at all.

I see no good way to combine this with the format 2, apart from the obvious ^(regex for 1,3,4|regex for 2)$ which is ugly, clumsy and makes it hard to get out the parts of the numbers.

As for the area code, you can add (\+\d)? to the beginning to capture a single-digit area code (sorry, I don't know the format of your area codes).

2

This code will match a US or Canadian phone number, and will also make sure that it is a valid area code and exchange:

^((\+1)?[\s-]?)?\(?[2-9]\d\d\)?[\s-]?[2-9]\d\d[\s-]?\d\d\d\d

Test on Regex101.com

2

Here's a regex that matches North American numbers as well as international numbers such as for middle east.

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

2

This is my Regex the worked on US numbers in the FreeCodeCamp phone number challenge:

/^\d{3}(-|\s)\d{3}(-|\s)\d{4}$|^\d{10}$|^1\s\d{3}(-|\s)\d{3}(-|\s)\d{4}$|^(1\s?)?\(\d{3}\)(\s|\-)?\d{3}\-\d{4}$/

Matches:

555-555-5555

(555)555-5555

(555) 555-5555

555 555 5555

5555555555

1 555 555 5555 etc
1

How about this?

^(\+?[01])?[-.\s]?\(?[1-9]\d{2}\)?[-.\s]?\d{3}[-.\s]?\d{4}

EDIT: I forgot about the () one. EDIT 2: Got the first 3 digit part wrong.

4
  • There is no need to escape dot . when in a character class, so [-\.\s] should actually be [-.\s], because we don't want to match a backslash. Commented May 22, 2013 at 18:37
  • Would it actually match the backslash? I thought it might not be necessary, but I wasn't 100% sure. Commented May 22, 2013 at 18:46
  • You are right. I have just tried it (I never needed a backslash before) and [\.] and [.] both match only dot, while [\\.] matches both dot and backslash. Thank you for your remark. Commented May 22, 2013 at 18:55
  • 1
    My opinion about regexes is that, if you are giving a regex to someone, always accompany it with an explanation, or the regex is worthless. Just my opinion.
    – John Red
    Commented Feb 10, 2017 at 5:42
1

Above regex is a slight modification of @Francis Gagnon.

Objective : To detect any possible pattern a user can share their US phone number


Version 1:

^\s*(?:\+?(\d{1,3}))?[\W\D\s]*(\d[\W\D\s]*?\d[\D\W\s]*?\d)[\W\D\s]*(\d[\W\D\s]*?\d[\D\W\s]*?\d)[\W\D\s]*(\d[\W\D\s]*?\d[\D\W\s]*?\d[\W\D\s]*?\d)(?: *x(\d+))?\s*$

Test it over here Codepen: https://codepen.io/kiranbhattarai/pen/NWKMXQO

Explanation of the regex : https://regexr.com/4kt5j


Version 2:

\s*(?:\+?(\d{1,3}))?[\W\D\s]^|()*(\d[\W\D\s]*?\d[\D\W\s]*?\d)[\W\D\s]*(\d[\W\D\s]*?\d[\D\W\s]*?\d)[\W\D\s]*(\d[\W\D\s]*?\d[\D\W\s]*?\d[\W\D\s]*?\d)(?: *x(\d+))?\s*$

What is in it: The test cases can be a part of the string. In version one the test cases should be a start of a line to work.

Codepen: https://codepen.io/kiranbhattarai/pen/GRKGNGG

Explanation of the regex : https://regexr.com/4kt9n


If you can find a pattern that can fail please do comment i will fix it.

Test Cases: Pass

8 0   0  4  4  4  5   55 5
1 800 555 1234
+1 800 555-1234
+86 800 555 1234
1-800-555-1234
1 (800) 555-1234
(800)555-1234
(800) 555-1234
(800)5551234
800-555-1234
800.555.1234
800 555 1234x5678
8005551234 x5678
1    800    555-1234
1----800----555-1234
800 (555) 1234
800(555)1234
8 0 0 5 5 5 1 2 3 4
8.0.0.5.5.5.1.2.3.4
8-0-0-5-5-5-1-2-3-4
(8)005551234
(80)05551234
8(00)5551234
8@0@0@5551234
8/0/0/5/5/5/1/2/3/4
8*0*0*5*5*5*1*2*3*4
8:0:0:5:5:5:1:2:3:4
8,0,0,5,5,5,1,2,3,4
800,555,1234
800:555:1234
1-718-444-1122
718-444-1122
(718)-444-1122
17184441122
7184441122
718.444.1122
1718.444.1122
1-123-456-7890
1 123-456-7890
1 (123) 456-7890
1 123 456 7890
1.123.456.7890
+91 (123) 456-7890
18005551234
1 800 555 1234
+1 800 555-1234
+86 800 555 1234
1-800-555-1234
1 (800) 555-1234
(800)555-1234
(800) 555-1234
(800)5551234
800-555-1234
800.555.1234
18001234567
1 800 123 4567
1-800-123-4567
+18001234567
+1 800 123 4567
+1 (800) 123 4567
1(800)1234567
+1800 1234567
1.8001234567
1.800.123.4567
+1 (800) 123-4567
18001234567
1 800 123 4567
+1 800 123-4567
+86 800 123 4567
1-800-123-4567
1 (800) 123-4567
(800)123-4567
(800) 123-4567
(800)1234567
800-123-4567
800.123.4567
1231231231
123-1231231
123123-1231
123-123 1231
123 123-1231
123-123-1231
(123)123-1231
(123) 123-1231
(123) 123 1231
+99 1234567890
+991234567890
(555) 444-6789
555-444-6789
555.444.6789
555 444 6789
1 800 555 1234
+1 800 555-1234
+86 800 555 1234
1-800-555-1234
1.800.555.1234
+1.800.555.1234
1 (800) 555-1234
(800)555-1234
(800) 555-1234
(800)5551234
800-555-1234
800.555.1234
(003) 555-1212
(103) 555-1212
(911) 555-1212
18005551234
1 800 555 1234
+86 800-555-1234
1 (800) 555-1234
2
  • +86, +99 etc are definitely not US phone numbers. Several of your other test cases look dubious for other reasons.
    – tripleee
    Commented Sep 12, 2019 at 17:28
  • @tripleee let me fix that, i have updated it to any country i hope it works. Additionally i removed the duplicate test cases as well Commented Sep 12, 2019 at 19:42
1

I'm just throwing this answer in there since it solves a problem of mine, it's based off of @stormy's answer, but includes 3 digit country codes and more importantly can be used anywhere in a string, but won't match is it's not preceded by a space/start of the string and ending with a word boundary. This is useful so that it won't match random numbers in the middle of a URL or something

((?:\s|^)(?:\+\d{1,3}\s?)?1?\-?\.?\s?\(?\d{3}\)?[\s.-]?\d{3}[\s.-]?\d{4})(?:\b)
1

I know this doesn't answer OP's question directly but if you are asking the same question as OP there is a good chance your are looking for a way to validate and store a phone number in either state or a database. Instead of trying to detect every possible combination of character that could be a phone number you might find it easier to break this task into multiple steps.

  1. strip out all none numbers
  2. strip out leading 1s
  3. make sure the number is at most 10 digits

Javascript pseudo example assuming "phone" is user input stored as a string:

phone.replace(/\D/g, "") 
phone.replace(/^1+/g, "") 
phone.slice(0, 10) 
phone.length === 10 ? "do something" : "don't do something"
  • Code above will need to be tweaked for your purposes and is left as simple as possible for none javascript readers.

For presentation purposes you can always layer dashes and leading 1s back in later but for storage you should probable only keep the actual numbers. This approach also has the added advantage of leaving you with some easy to digest regular expressions.

0
^(\+1)?\s?(\([1-9]\d{2}\)|[1-9]\d{2})(-|\s|.)\d{3}(-|\s|.)\d{4}
0

This is a more comprehensive version that will match as much as I can think of as well as give you group matching for country, region, first, and last.

(?<number>(\+?(?<country>(\d{1,3}))(\s|-|\.)?)?(\(?(?<region>(\d{3}))\)?(\s|-|\.)?)((?<first>(\d{3}))(\s|-|\.)?)((?<last>(\d{4}))))
0

I ended up with

const regexBase = '(?:\\+?(\\d{1,3}))?[-. (]*(\\d{3})?[-. )]*(\\d{3})[-. ]*(\\d{4,5})(?: *x(\\d+))?'; const phoneRegex = new RegExp('\\s*' + regexBase + '\\s*', 'g');

this was to allow for things like dutch numbers, for example

+358 300 20200

0
/^([+]?[1]?(1 )?[-.+]?\(?\d{1}[- .+]*\d{1}[- .+]*\d{1}\)?[- .+]*\d{1}[- .+]*\d{1}[- .+]*\d{1}[- .+]*\d{1}[- .+]*\d{1}[- .+]*\d{1}[- .+]*\d{1})$/

It's perfect for any phone number format with at least 10 digits.

0

Here is a regex that will match any phone number for every country in the world regardless of the number of digits. It matches formatted and unformatted national and international phone numbers.

// This will match any phone number in a file
const pattern = /(\+)?(\(?\d+\)?)(([\s-]+)?(\d+)){0,}/g

// If you want to match phone numbers line by line consider
// adding '^' at beginning of regex and '$' at end of it
// like below
const pattern = /^(\+)?(\(?\d+\)?)(([\s-]+)?(\d+)){0,}$/g

If you want to adjust it to match a certain number of digits, you can do that easily.

Example of phone numbers that it will match:

Afghanistan:

  • Formatted: (020) 1234 5678
  • Unformatted: +932012345678

Albania:

  • Formatted: (04) 234 5678
  • Unformatted: +35542345678

Algeria:

  • Formatted: (021) 234 5678
  • Unformatted: +213212345678

Andorra:

  • Formatted: (07) 123 456
  • Unformatted: +3767123456

Angola:

  • Formatted: (222) 123 456
  • Unformatted: +244222123456

Antigua and Barbuda:

  • Formatted: (268) 123 4567
  • Unformatted: +12681234567

Argentina:

  • Formatted: (011) 1234-5678
  • Unformatted: +541112345678

Armenia:

  • Formatted: (010) 123456
  • Unformatted: +37410123456

Australia:

  • Formatted: (02) 1234 5678
  • Unformatted: +61212345678

Austria:

  • Formatted: (01) 2345678
  • Unformatted: +4312345678

Azerbaijan:

  • Formatted: (012) 345 67 89
  • Unformatted: +994123456789

The Bahamas:

  • Formatted: (242) 456-7890
  • Unformatted: +12424567890

Bahrain:

  • Formatted: (01) 234 567
  • Unformatted: +9731234567

Bangladesh:

  • Formatted: (02) 12345678
  • Unformatted: +880212345678

Barbados:

  • Formatted: (246) 234-5678
  • Unformatted: +12462345678

Belarus:

  • Formatted: (017) 123-45-67
  • Unformatted: +375171234567

Belgium:

  • Formatted: (012) 34 56 78
  • Unformatted: +3212345678

Belize:

  • Formatted: (501) 234-5678
  • Unformatted: +5012345678

Benin:

  • Formatted: (21) 12 34 56
  • Unformatted: +22921123456

Bhutan:

  • Formatted: (02) 334 567
  • Unformatted: +9752334567

Bolivia:

  • Formatted: (02) 1234567
  • Unformatted: +59121234567

Bosnia and Herzegovina:

  • Formatted: (033) 123-456
  • Unformatted: +38733123456

Botswana:

  • Formatted: (02) 123 4567
  • Unformatted: +26721234567

Brazil:

  • Formatted: (11) 1234-5678
  • Unformatted: +551112345678

Brunei:

  • Formatted: (03) 123 4567
  • Unformatted: +67331234567

Bulgaria:

  • Formatted: (02) 123 4567
  • Unformatted: +35921234567

Burkina Faso:

  • Formatted: (25) 12 34 56
  • Unformatted: +22625123456

Burundi:

  • Formatted: (22) 12 34 56
  • Unformatted: +25722123456

Cabo Verde:

  • Formatted: (261) 23 45 67
  • Unformatted: +238261234567

Cambodia:

  • Formatted: (023) 123 456
  • Unformatted: +85523123456

Cameroon:

  • Formatted: (22) 12 34 56
  • Unformatted: +23722123456

Canada:

  • Formatted: (416) 555-1234
  • Unformatted: +14165551234

Central African Republic:

  • Formatted: (21) 12 34 56
  • Unformatted: +23621123456

Chad:

  • Formatted: (225) 12 34 56
  • Unformatted: +235225123456

Chile:

  • Formatted: (02) 1234 5678
  • Unformatted: +56212345678

China:

  • Formatted: (010) 1234-5678
  • Unformatted: +861012345678

Colombia:

  • Formatted: (1) 2345678
  • Unformatted: +5712345678

Comoros:

  • Formatted: (269) 23 45 67
  • Unformatted: +269269234567

Congo, Democratic Republic of the:

  • Formatted: (12) 34 56789
  • Unformatted: +243123456789

Congo, Republic of the:

  • Formatted: (22) 12 34 56
  • Unformatted: +24222123456

Costa Rica:

  • Formatted: (02) 1234 5678
  • Unformatted: +506212345678

Côte d’Ivoire:

  • Formatted: (20) 12 34 56
  • Unformatted: +22520123456

Croatia:

  • Formatted: (01) 234 5678
  • Unformatted: +38512345678

Cuba:

  • Formatted: (07) 1234567
  • Unformatted: +5371234567

Cyprus:

  • Formatted: (022) 123456
  • Unformatted: +35722123456

Czech Republic:

  • Formatted: (02) 1234 5678
  • Unformatted: +420212345678

Denmark:

  • Formatted: (32) 12 34 56
  • Unformatted: +4532123456

Djibouti:

  • Formatted: (21) 12 34 56
  • Unformatted: +25321123456

Dominica:

  • Formatted: (767) 235-6789
  • Unformatted: +17672356789

Dominican Republic:

  • Formatted: (809) 234-5678
  • Unformatted: +18092345678

East Timor (Timor-Leste):

  • Formatted: (333) 12 345
  • Unformatted: +67033312345

Ecuador:

  • Formatted: (02) 123 4567
  • Unformatted: +59321234567

Egypt:

  • Formatted: (02) 12345678
  • Unformatted: +20212345678

El Salvador:

  • Formatted: (2222) 1234
  • Unformatted: +50322221234

Equatorial Guinea:

  • Formatted: (333) 12 34 56
  • Unformatted: +240333123456

Eritrea:

  • Formatted: (1) 23 45 67
  • Unformatted: +2911234567

Estonia:

  • Formatted: (07) 234 5678
  • Unformatted: +37272345678

Eswatini:

  • Formatted: (240) 23456
  • Unformatted: +26824023456

Ethiopia:

  • Formatted: (011) 123 4567
  • Unformatted: +251111234567

Fiji:

  • Formatted: (331) 2345
  • Unformatted: +6793312345

Finland:

  • Formatted: (02) 1234567
  • Unformatted: +35821234567

France:

  • Formatted: (01) 23 45 67 89
  • Unformatted: +33123456789

Gabon:

  • Formatted: (01) 23 45 67
  • Unformatted: +2411234567

The Gambia:

  • Formatted: (20) 1234567
  • Unformatted: +220201234567

Georgia:

  • Formatted: (032) 123 456
  • Unformatted: +99532123456

Germany:

  • Formatted: (030) 12345678
  • Unformatted: +493012345678

Ghana:

  • Formatted: (030) 123 4567
  • Unformatted: +233301234567

Greece:

  • Formatted: (210) 1234567
  • Unformatted: +302101234567

Grenada:

  • Formatted: (473) 234-5678
  • Unformatted: +14732345678

Guatemala:

  • Formatted: (02) 3456 7890
  • Unformatted: +502234567890

Guinea:

  • Formatted: (30) 12 34 56
  • Unformatted: +22430123456

Guinea-Bissau:

  • Formatted: (245) 23 45 67
  • Unformatted: +245245234567

Guyana:

  • Formatted: (592) 234-5678
  • Unformatted: +5922345678

Haiti:

  • Formatted: (509) 34 56 78 90
  • Unformatted: +50934567890

Honduras:

  • Formatted: (504) 2345-6789
  • Unformatted: +50423456789

Hungary:

  • Formatted: (01) 234 5678
  • Unformatted: +3612345678

Iceland:

  • Formatted: (415) 123-4567
  • Unformatted: +3544151234567

India:

  • Formatted: (080) 12345 678
  • Unformatted: +918012345678

Indonesia:

  • Formatted: (021) 1234567
  • Unformatted: +62211234567

Iran:

  • Formatted: (021) 2345 6789
  • Unformatted: +982123456789

Iraq:

  • Formatted: (01) 234 5678
  • Unformatted: +96412345678

Ireland:

  • Formatted: (01) 123 4567
  • Unformatted: +35311234567

Israel:

  • Formatted: (02) 123 4567
  • Unformatted: +97221234567

Italy:

  • Formatted: (02) 1234 5678
  • Unformatted: +390212345678

Jamaica:

  • Formatted: (876) 234-5678
  • Unformatted: +18762345678

Japan:

  • Formatted: (03) 1234 5678
  • Unformatted: +81312345678

Jordan:

  • Formatted: (06) 123 4567
  • Unformatted: +96261234567

Kazakhstan:

  • Formatted: (727) 123 4567
  • Unformatted: +77271234567

Kenya:

  • Formatted: (020) 1234567
  • Unformatted: +254201234567

Kiribati:

  • Formatted: (751) 23 45
  • Unformatted: +6867512345

Korea, North:

  • Formatted: (02) 1234 5678
  • Unformatted: +850212345678

Korea, South:

  • Formatted: (02) 1234 5678
  • Unformatted: +82212345678

Kosovo:

  • Formatted: (038) 123 456
  • Unformatted: +38338123456

Kuwait:

  • Formatted: (02) 123 4567
  • Unformatted: +96521234567

Kyrgyzstan:

  • Formatted: (312) 12 34 56
  • Unformatted: +996312123456

Laos:

  • Formatted: (021) 234 567
  • Unformatted: +85621234567

Latvia:

  • Formatted: (06) 123 4567
  • Unformatted: +37161234567

Lebanon:

  • Formatted: (01) 234 567
  • Unformatted: +9611234567

Lesotho:

  • Formatted: (22) 123 456
  • Unformatted: +26622123456

Liberia:

  • Formatted: (01) 123 456
  • Unformatted: +2311123456

Libya:

  • Formatted: (021) 234 5678
  • Unformatted: +218212345678

Liechtenstein:

  • Formatted: (234) 567 890
  • Unformatted: +423234567890

Lithuania:

  • Formatted: (08) 123 4567
  • Unformatted: +37081234567

Luxembourg:

  • Formatted: (02) 123 456
  • Unformatted: +3522123456

Madagascar:

  • Formatted: (20) 12 345 67
  • Unformatted: +261201234567

Malawi:

  • Formatted: (01) 234 5678
  • Unformatted: +26512345678

Malaysia:

  • Formatted: (03) 1234 5678
  • Unformatted: +60312345678

Maldives:

  • Formatted: (331) 2345
  • Unformatted: +9603312345

Mali:

  • Formatted: (20) 12 34 56
  • Unformatted: +22320123456

Malta:

  • Formatted: (21) 234 567
  • Unformatted: +35621234567

Marshall Islands:

  • Formatted: (692) 234-5678
  • Unformatted: +6922345678

Mauritania:

  • Formatted: (45) 12 34 56
  • Unformatted: +22245123456

Mauritius:

  • Formatted: (230) 123 4567
  • Unformatted: +2301234567

Mexico:

  • Formatted: (55) 1234 5678
  • Unformatted: +525512345678

Micronesia, Federated States of:

  • Formatted: (691) 320 1234
  • Unformatted: +6913201234

Moldova:

  • Formatted: (022) 123 456
  • Unformatted: +37322123456

Monaco:

  • Formatted: (377) 1234 5678
  • Unformatted: +37712345678

Mongolia:

  • Formatted: (11) 123 456
  • Unformatted: +97611123456

Montenegro:

  • Formatted: (020) 123 456
  • Unformatted: +38220123456

Morocco:

  • Formatted: (052) 123 4567
  • Unformatted: +212521234567

Mozambique:

  • Formatted: (21) 123 456
  • Unformatted: +25821123456

Myanmar (Burma):

  • Formatted: (01) 234 567
  • Unformatted: +9511234567

Namibia:

  • Formatted: (061) 123 4567
  • Unformatted: +264611234567

Nauru:

  • Formatted: (674) 444 5678
  • Unformatted: +6744445678

Nepal:

  • Formatted: (01) 2345678
  • Unformatted: +97712345678

Netherlands:

  • Formatted: (020) 123 4567
  • Unformatted: +31201234567

New Zealand:

  • Formatted: (09) 123 4567
  • Unformatted: +6491234567

Nicaragua:

  • Formatted: (505) 2345 6789
  • Unformatted: +50523456789

Niger:

  • Formatted: (20) 12 34 56
  • Unformatted: +22720123456

Nigeria:

  • Formatted: (01) 234 5678
  • Unformatted: +23412345678

North Macedonia:

  • Formatted: (02) 123 4567
  • Unformatted: +38921234567

Norway:

  • Formatted: (02) 123 456
  • Unformatted: +472123456

Oman:

  • Formatted: (02) 1234 5678
  • Unformatted: +968212345678

Pakistan:

  • Formatted: (021) 1234567
  • Unformatted: +92211234567

Palau:

  • Formatted: (680) 488 1234
  • Unformatted: +6804881234

Panama:

  • Formatted: (212) 345-6789
  • Unformatted: +5072123456789

Papua New Guinea:

  • Formatted: (675) 123 4567
  • Unformatted: +6751234567

Paraguay:

  • Formatted: (021) 1234567
  • Unformatted: +59521234567

Peru:

  • Formatted: (01) 1234567
  • Unformatted: +5111234567

Philippines:

  • Formatted: (02) 123 4567
  • Unformatted: +6321234567

Poland:

  • Formatted: (12) 345 67 89
  • Unformatted: +48123456789

Portugal:

  • Formatted: (01) 234 5678
  • Unformatted: +35112345678

Qatar:

  • Formatted: (4017) 0123
  • Unformatted: +97440170123

Romania:

  • Formatted: (021) 123 4567
  • Unformatted: +40211234567

Russia:

  • Formatted: (812) 123-45-67
  • Unformatted: +78121234567

Rwanda:

  • Formatted: (250) 123 456 789
  • Unformatted: +250123456789

Saint Kitts and Nevis:

  • Formatted: (869) 765-1234
  • Unformatted: +18697651234

Saint Lucia:

  • Formatted: (758) 234-5678
  • Unformatted: +17582345678

Saint Vincent and the Grenadines:

  • Formatted: (784) 456-7890
  • Unformatted: +17844567890

Samoa:

  • Formatted: (685) 23456
  • Unformatted: +68523456

San Marino:

  • Formatted: (0549) 123456
  • Unformatted: +378549123456

Sao Tome and Principe:

  • Formatted: (981) 23 45
  • Unformatted: +2399812345

Saudi Arabia:

  • Formatted: (01) 234 5678
  • Unformatted: +96612345678

Senegal:

  • Formatted: (33) 123 45 67
  • Unformatted: +221331234567

Serbia:

  • Formatted: (011) 1234567
  • Unformatted: +38111234567

Seychelles:

  • Formatted: (248) 2 34 56
  • Unformatted: +24823456

Sierra Leone:

  • Formatted: (22) 123456
  • Unformatted: +23222123456

Singapore:

  • Formatted: (02) 1234 5678
  • Unformatted: +65612345678

Slovakia:

  • Formatted: (02) 1234 5678
  • Unformatted: +421212345678

Slovenia:

  • Formatted: (01) 234 56 78
  • Unformatted: +38612345678

Solomon Islands:

  • Formatted: (677) 23456
  • Unformatted: +67723456

Somalia:

  • Formatted: (061) 1234567
  • Unformatted: +252611234567

South Africa:

  • Formatted: (011) 234 5678
  • Unformatted: +27112345678

Spain:

  • Formatted: (91) 123 45 67
  • Unformatted: +34911234567

Sri Lanka:

  • Formatted: (011) 234 5678
  • Unformatted: +94112345678

Sudan:

  • Formatted: (012) 345 6789
  • Unformatted: +249123456789

Sudan, South:

  • Formatted: (011) 123 4567
  • Unformatted: +21111234567

Suriname:

  • Formatted: (597) 123456
  • Unformatted: +597123456

Sweden:

  • Formatted: (08) 123 456 78
  • Unformatted: +46812345678

Switzerland:

  • Formatted: (044) 123 45 67
  • Unformatted: +41441234567

Syria:

  • Formatted: (011) 1234567
  • Unformatted: +96311234567

Taiwan:

  • Formatted: (02) 1234 5678
  • Unformatted: +886212345678

Tajikistan:

  • Formatted: (372) 12 34 56
  • Unformatted: +992372123456

Tanzania:

  • Formatted: (022) 234 5678
  • Unformatted: +255222345678

Thailand:

  • Formatted: (02) 123 4567
  • Unformatted: +6621234567

Togo:

  • Formatted: (22) 12 34 56
  • Unformatted: +22822123456

Tonga:

  • Formatted: (22) 12345
  • Unformatted: +6762212345

Trinidad and Tobago:

  • Formatted: (868) 234-5678
  • Unformatted: +18682345678

Tunisia:

  • Formatted: (71) 234 567
  • Unformatted: +21671234567

Turkey:

  • Formatted: (0212) 345 67 89
  • Unformatted: +902123456789

Turkmenistan:

  • Formatted: (12) 34 56 78
  • Unformatted: +99312345678

Tuvalu:

  • Formatted: (688) 23 456
  • Unformatted: +68823456

Uganda:

  • Formatted: (041) 1234567
  • Unformatted: +256411234567

Ukraine:

  • Formatted: (044) 123 45 67
  • Unformatted: +380441234567

United Arab Emirates:

  • Formatted: (02) 123 4567
  • Unformatted: +97121234567

United Kingdom:

  • Formatted: (020) 1234 5678
  • Unformatted: +442012345678

United States:

  • Formatted: (212) 555-1234
  • Unformatted: +12125551234

Uruguay:

  • Formatted: (02) 123 4567
  • Unformatted: +59821234567

Uzbekistan:

  • Formatted: (71) 123 45 67
  • Unformatted: +998711234567

Vanuatu:

  • Formatted: (555) 2345
  • Unformatted: +6785552345

Vatican City:

  • Formatted: (06) 6982 0026
  • Unformatted: +390669820026

Venezuela:

  • Formatted: (0212) 123 45 67
  • Unformatted: +582121234567

Vietnam:

  • Formatted: (024) 1234 5678
  • Unformatted: +842412345678

Yemen:

  • Formatted: (01) 234 567
  • Unformatted: +9671234567

Zambia:

  • Formatted: (021) 1234567
  • Unformatted: +260211234567

Zimbabwe:

  • Formatted: (024) 12345
  • Unformatted: +2632412345

Not the answer you're looking for? Browse other questions tagged or ask your own question.