My regex of choice is:

/^[\+]?[0-9]{0,3}\W?+[(]?[0-9]{3}[)]?[-\s\.]?[0-9]{3}[-\s\.]?[0-9]{4,6}$/im

Valid formats:

(123) 456-7890
(123)456-7890
123-456-7890
123.456.7890
1234567890
+31636363634
075-63546725
+1 (415)-555-1212
+1 (123) 456-7890
+1 (123)456-7890
+1 123-456-7890
+1 123.456.7890
+1 1234567890
+1 075-63546725
+12 (415)-555-1212
+12 (123) 456-7890
+12 (123)456-7890
+12 123-456-7890
+12 123.456.7890
+12 1234567890
+123 075-63546725
+123 (415)-555-1212
+123 (123) 456-7890
+123 (123)456-7890
+123 123-456-7890
+123 123.456.7890
+123 1234567890
+123 075-63546725
+1(415)-555-1212
+1(123) 456-7890
+1(123)456-7890
+1123-456-7890
+1123.456.7890
+11234567890
+1075-63546725
+12(415)-555-1212
+12(123) 456-7890
+12(123)456-7890
+12123-456-7890
+12123.456.7890
+121234567890
+123075-63546725
+123(415)-555-1212
+123(123) 456-7890
+123(123)456-7890
+123123-456-7890
+123123.456.7890
+1231234567890
+123075-63546725
Answer from EeeeeK on Stack Overflow
Top answer
1 of 16
259

My regex of choice is:

/^[\+]?[0-9]{0,3}\W?+[(]?[0-9]{3}[)]?[-\s\.]?[0-9]{3}[-\s\.]?[0-9]{4,6}$/im

Valid formats:

(123) 456-7890
(123)456-7890
123-456-7890
123.456.7890
1234567890
+31636363634
075-63546725
+1 (415)-555-1212
+1 (123) 456-7890
+1 (123)456-7890
+1 123-456-7890
+1 123.456.7890
+1 1234567890
+1 075-63546725
+12 (415)-555-1212
+12 (123) 456-7890
+12 (123)456-7890
+12 123-456-7890
+12 123.456.7890
+12 1234567890
+123 075-63546725
+123 (415)-555-1212
+123 (123) 456-7890
+123 (123)456-7890
+123 123-456-7890
+123 123.456.7890
+123 1234567890
+123 075-63546725
+1(415)-555-1212
+1(123) 456-7890
+1(123)456-7890
+1123-456-7890
+1123.456.7890
+11234567890
+1075-63546725
+12(415)-555-1212
+12(123) 456-7890
+12(123)456-7890
+12123-456-7890
+12123.456.7890
+121234567890
+123075-63546725
+123(415)-555-1212
+123(123) 456-7890
+123(123)456-7890
+123123-456-7890
+123123.456.7890
+1231234567890
+123075-63546725
2 of 16
159

First off, your format validator is obviously only appropriate for NANP (country code +1) numbers. Will your application be used by someone with a phone number from outside North America? If so, you don't want to prevent those people from entering a perfectly valid [international] number.

Secondly, your validation is incorrect. NANP numbers take the form NXX NXX XXXX where N is a digit 2-9 and X is a digit 0-9. Additionally, area codes and exchanges may not take the form N11 (end with two ones) to avoid confusion with special services except numbers in a non-geographic area code (800, 888, 877, 866, 855, 900) may have a N11 exchange.

So, your regex will pass the number (123) 123 4566 even though that is not a valid phone number. You can fix that by replacing \d{3} with [2-9]{1}\d{2}.

Finally, I get the feeling you're validating user input in a web browser. Remember that client-side validation is only a convenience you provide to the user; you still need to validate all input (again) on the server.

TL;DR don't use a regular expression to validate complex real-world data like phone numbers or URLs. Use a specialized library.

🌐
UI Bakery
uibakery.io › regex-library › phone-number
Phone number regex
This regular expression will match phone numbers entered with delimiters (spaces, dots, brackets, etc.) /^\+?\d{1,4}?[-.\s]?\(?\d{1,3}?\)?[-.\s]?\d{1,4}[-.\s]?\d{1,4}[-.\s]?\d{1,9}$/ ... var regex = /^\+?\d{1,4}?[-.\s]?\(?\d{1,3}?\)?[-.\s]?\d{1,4}[-.\s]?\d{1,4}[-.\s]?\d{1,9}$/; regex.test('+1 ...
Discussions

regex - Regular Expression to reformat a US phone number in Javascript - Stack Overflow
I'm looking to reformat (replace, not validate - there are many references for validating) a phone number for display in Javascript. Here's an example of some of the data: 123 4567890 (123) 456-789... More on stackoverflow.com
🌐 stackoverflow.com
Javascript Regex - What to use to validate a phone number? - Stack Overflow
Could anyone tell me what RegEx would work to validate an international phone number including white space between the numbers and also allowing for these chars: - ( ). The amount of numbers in the string is not too important, I would just like the user to be able to type something like either example ... More on stackoverflow.com
🌐 stackoverflow.com
regex - Validate phone number using javascript - Stack Overflow
If you had included $ or \b at ... the last number - the 7 - and it is not a word boundary \b nor a an end of line $ so it stops and fails to find a match. ... This regex fails for (078)789-8908 too. See my comment at Andy's post. 2013-08-22T09:17:58.52Z+00:00 ... This one fails for (078)789-8908 because of the space. You should add a ? there. 2013-08-22T09:16:17.763Z+00:00 ... There isn't a space in the example in the question, ... More on stackoverflow.com
🌐 stackoverflow.com
How to Match a Phone Number with Regex and JavaScript
Validating a phone number WITHOUT regex becomes an obnoxious leetcode question def phone_number(number) allowed_characters = ["1", "2", "3", "4", "5", "6", "7", "8", "9", "0"] normalized_number = "" number.each_char do |c| normalized_number += c if allowed_characters.include?(c) end normalized_number end Let's not exaggerate. Well, if I really wanted to I could pretty much make it into a one liner too: "(123-456-789)".split('').select {|s| (48..57).to_a.map(&:chr).include?(s)}.join => "123456789" Ruby syntax but Python and most other languages are kinda similar. More on reddit.com
🌐 r/learnprogramming
3
0
July 16, 2022
🌐
Voximplant
voximplant.com › blog › javascript-regular-expression-for-phone-number-verification
JavaScript Regular Expression for Phone Number ...
Using the conventions described above, the example E.164 phone number is +447911651780. The goal of the international phone number standard is to have valid telephone numbers represented consistently.
🌐
GitHub
gist.github.com › jengle-dev › a327f2b58e08f384ec41dbb5e5454c28
RegEx Phone Number Matching & Validation · GitHub
Clone this repository at <script src="https://gist.github.com/jengle-dev/a327f2b58e08f384ec41dbb5e5454c28.js"></script> Save jengle-dev/a327f2b58e08f384ec41dbb5e5454c28 to your computer and use it in GitHub Desktop. ... This 'Regular Expression' (RegEx) is used to match and validate US phone numbers in the following formats, where X represents digits (d): ... Another Example with additional parameters on limiting input to 0-9: \(?([0-9]{3})\)?[-. ]?([0-9]{3})[-. ]?([0-9]{4})$/
🌐
Kevinleary
kevinleary.net › blog › validating-real-phone-numbers-javascript
Kevinleary.net: JavaScript Phone Number Validation: Regex & libphonenumber-js
December 8, 2024 - For example, validating a North American phone number format: function validatePhoneNumber(phoneNumber) { const regex = /^\+?1?\d{10}$/; // Matches +1XXXXXXXXXX or XXXXXXXXXX return regex.test(phoneNumber); }
Find elsewhere
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › how-to-validate-phone-numbers-using-javascript
How to Validate Phone Numbers Using JavaScript - GeeksforGeeks
July 23, 2025 - For phone number validation, we'll use Regex to define patterns that match the common formats of phone numbers. By applying different patterns, we can validate phone numbers with or without special characters like parentheses, spaces, or hyphens.
🌐
Reddit
reddit.com › r/learnprogramming › how to match a phone number with regex and javascript
r/learnprogramming on Reddit: How to Match a Phone Number with Regex and JavaScript
July 16, 2022 -

I'll be honest, the first time I saw a regular expression, it was a scary experience. It looks like a weird alien language! I thought to myself: "I've spent months learning programming and now i gotta learn this seemly super complex language!?"

However, once I sat down to actually learn regex, I discovered it's not super hard, once you learn the syntax.

Why should I even bother Learning Regex?

As you start coding more, and more, it really comes in handy in all types of situations, and not just to valid phone numbers, and email addresses. It's very helpful when extract data from logs, messy JSON data from API calls, and many other situations.

I'm going to teach you how to valid a phone number with 1 line of code, with 1 regular expression. **Validating a phone number WITHOUT regex becomes an obnoxious leetcode question. ** 😧

Why is validating a phone number so complex?

Let's say you have a form on your website to collect a phone number to spa-, I mean, SMS your subscribers, there are a bunch of different ways you could submit their phone numbers.

All of these are VALID US based numbers:

  • 202-515-5555

  • 202 515 5555

  • (202)515 5555

  • 1 202 515 5555

  • 2025155555

  • 1-202-515-5555

  • 1202-515-5555

  • etc

There are more valid combinations I didn't list, but you get the idea! Validating every combo because a nasty coding problem. *But not if you're using regex to validate it! * 😉

🌐
Qodex
qodex.ai › home › all tools › getting started › phone number regex javascript validator
Phone Number Regex JavaScript Validator — Test Patterns
Regex patterns often use backreferences ... separator—space, dash, or dot—can appear between sections: for example, "(123) 456-7890" or "123.456.7890"....
Rating: 4.9 ​ - ​ 60 votes
🌐
Indepth JavaScript
indepthjavascript.dev › how-to-match-a-phone-number-with-regex-and-javascript
Match a Phone Number with Regex and JavaScript
July 27, 2022 - Now we want to optionally add a dash or space after the 1. Luckily, we already know how to do that: `[ -]?'. ... Can you sense there's something wrong here? The above regex string match MUST start with 1, it's not optional.
🌐
Delft Stack
delftstack.com › home › howto › javascript › phone number regex javascript
Phone Number RegEx in JavaScript | Delft Stack
October 12, 2023 - const regEx = /pattern/; const regEx = new RegExp('pattern'); ... <form name="form1"> <input type='text' id="phoneNumber" name='text1'/> <button type="submit" name="submit" onclick="phonenumber()">Submit</button> </form> function phonenumber() ...
🌐
W3Resource
w3resource.com › javascript › form › phone-no-validation.php
JavaScript : phone number validation - w3resource
In this page we have discussed how to validate a phone number (in different format) using JavaScript : At first, we validate a phone number of 10 digits with no comma, no spaces, no punctuation and there will be no + sign in front the number.
🌐
SitePoint
sitepoint.com › javascript
Phone Number Regular Expression Validation - JavaScript
October 2, 2005 - I’ve found plenty, but it turns out that most of them appear on the surface to be fine, but in reality they don’t actually work, like this one: //Example, try this out for yourself var phoneRegEx = /\\(?\\d{3}\\)?[-\\/\\.\\s]?\\d{3}[-\\...
🌐
freeCodeCamp
forum.freecodecamp.org › javascript
Regex for US phone number - JavaScript
December 3, 2021 - **Your code so far** function telephoneCheck(str) { return /^[\+]?([0-9][\s]?|[0-9]?)([(][0-9]{3}[)][\s]?|[0-9]{3}[-\s\.]?)[0-9]{3}[-\s\.]?[0-9]{4,6}$/ig.test(str); } telephoneCheck("555-555-5555"); **Your browser information:** User Agent is: ...
🌐
Stack Abuse
stackabuse.com › validate-phone-numbers-in-javascript-with-regular-expressions
Validate Phone Numbers in JavaScript with Regular Expressions
June 7, 2023 - The function is quite straightforward. It takes a phone number as input. The regular expression pattern is stored inside a variable called pattern. The pattern is instantiated using the RegExp constructor and passing the expression as a parameter to the constructor.
Top answer
1 of 4
4

So, first, I should point out that requiring US-formatted telephone numbers is pretty restrictive; international numbers can have very different rules. That said, this regex should meet your needs:

/(?:^|\D)\(([2-9])(?:\d(?!\1)\d|(?!\1)\d\d)\)\s*[2-9]\d{2}-\d{4}/

First,to prevent matching things that end with a valid phone number but have extra junk up front, we match either the start of the string (^) or a non-digit (\D). Then the opening parenthesis of the area code, (\().

Then we match the first digit of the area code, [2-9].

Then we match either any digit (\d) followed by any digit except the first one ((?!\1)\d), or the other way around ((?!\1)\d\d). This keeps the area code from being three identical digits.

Then we close the parens (\)), allow (but don't require) space (\s*) before the first digit of the prefix ([2-9] again), followed by any two digits (\d{2}), a hyphen, and any four digits (\d{4}).

2 of 4
2

Let's go by parts, you got three conditions:

  1. ALL 9 digits being 0 is not allowed
  2. The area code (first 3 digits) cannot be the same digit,
  3. The 1st and 4th digit cannot be 0 or 1.

Condition 1 is redundant if you consider condition 3; A simple regex not considering condition 2 is:

/^\([2-9]\d\d\) [2-9]\d\d-\d{4}$/

Assuming you want parenthesis and spaces - (555) 555-5555

Explanation:

  • \d matches any digit
  • [2-9] matches any character from 2 to 9
  • space and dash are literals - match spaces and dash
  • {4} is a quantifier - will match 4 digits in this case
  • ( and ) are escaped literals - will match ( and ) respectively

Now if we want to consider condition number 2 in our expression, we use

  • a negative lookahead ?!
  • a capturing group () and
  • a back reference \1.

Read some regex reference if you want to fully understand those. The full expression is:

^\(([2-9])(?!\1\1)\d\d\) [2-9]\d\d-\d{4}$
🌐
DEV Community
dev.to › johnnyturco › what-are-regular-expressions-using-a-simple-javascript-regular-expression-to-format-phone-numbers-2cgh
What Are Regular Expressions? A Simple JavaScript Regex to Format Phone Numbers - DEV Community
December 9, 2022 - I was recently working with an API that returned (U.S.) phone numbers as a 10-digit string (e.g., 5557071234), and I needed a way to convert these numbers into a more readable format, like (555) 707-1234.