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 (615) 243-5172'); // returns true
Discussions

Phone Number Regular Expression Validation - JavaScript - SitePoint Forums | Web Development & Design Community
Howdy I’ve been searching for a decent phone number regular expression validation and it turns out a lot harder to dig one up than I expected. 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: ... More on sitepoint.com
🌐 sitepoint.com
0
October 2, 2005
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
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 More on stackoverflow.com
🌐 stackoverflow.com
regex - Validate phone number using javascript - Stack Overflow
This is by far the easiest way I have found to use javascript regex to check phone number format. More on stackoverflow.com
🌐 stackoverflow.com
People also ask

What’s the best way to clean user input before regex?
Use .trim() and optionally .replace(/\s/g, "") to remove extra spaces.
🌐
qodex.ai
qodex.ai › home › all tools › getting started › phone number regex javascript validator
Phone Number Regex JavaScript Validator — Test Patterns
Can this regex validate all global formats?
It covers many formats, but specific countries may require custom patterns.
🌐
qodex.ai
qodex.ai › home › all tools › getting started › phone number regex javascript validator
Phone Number Regex JavaScript Validator — Test Patterns
How can I create a regular expression that only allows certain characters (digits, +, (), -,., and spaces) in phone numbers?
To make sure your input contains only valid characters for phone numbers, use this handy regular expression: /[^0-9+() -.]/g This pattern matches any character that isn't a digit, plus, parenthesis, space, period, or hyphen—helping you quickly spot and remove unwanted symbols from user input. Combined with the previous tips, this gives you a solid foundation for robust phone number validation.
🌐
qodex.ai
qodex.ai › home › all tools › getting started › phone number regex javascript validator
Phone Number Regex JavaScript Validator — Test Patterns
🌐
O'Reilly
oreilly.com › library › view › regular-expressions-cookbook › 9781449327453 › ch04s02.html
4.2. Validate and Format North American Phone Numbers - Regular Expressions Cookbook, 2nd Edition [Book]
August 27, 2012 - ProblemSolutionSimpleSimple, with restrictions on charactersSimple, with all valid local part charactersNo leading, trailing, or consecutive dotsTop-level domain has two to six lettersDiscussionAbout email addressesRegular expression syntaxBuilding a regex step-by-stepVariationsSee Also · ProblemSolutionRegular expressionReplacementC# exampleJavaScript exampleOther programming languagesDiscussionVariationsEliminate invalid phone numbersFind phone numbers in documentsAllow a leading “1”Allow seven-digit phone numbersSee Also · ProblemSolutionRegular expressionJavaScript exampleDiscussionVariationsValidate international phone numbers in EPP formatSee Also
Authors   Jan GoyvaertsSteven Levithan
Published   2012
Pages   609
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › how-to-validate-phone-numbers-using-javascript
How to Validate Phone Numbers Using JavaScript - GeeksforGeeks
July 23, 2025 - Validation: It ensures the phone number is exactly 10 digits long by using the Regex pattern /^\d{10}$/. Invalid Characters: It prevents errors if the phone number starts or ends with spaces or hyphens.
🌐
Voximplant
voximplant.com › blog › javascript-regular-expression-for-phone-number-verification
JavaScript Regular Expression for Phone Number ...
Below, we will discuss the Libphonenumber-js version of that library which provides better optimization and more features compared to Google's auto-generated JavaScript port. The Libphonenumber-js library can format, parse, and validate international telephone numbers using the following scripts: getNumberType – Determines the type of a valid phone number.
🌐
Stack Abuse
stackabuse.com › validate-phone-numbers-in-javascript-with-regular-expressions
Validate Phone Numbers in JavaScript with Regular Expressions
June 7, 2023 - Using literal notation, where a pattern is formatted between two forward slashes · Using constructor notation, where either a string or a RegExp object is passed ... On the other hand, with constructor notation, you'll need to use the RegExp constructor to create an instance of it. Here's how it looks: ... You can read more about the RegExp object from the official MDN docs. Now, let's explore the importance of phone number validation and the various components of a phone number.
Find elsewhere
🌐
SitePoint
sitepoint.com › javascript
Phone Number Regular Expression Validation - JavaScript - SitePoint Forums | Web Development & Design Community
October 2, 2005 - Howdy I’ve been searching for a decent phone number regular expression validation and it turns out a lot harder to dig one up than I expected. 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}[-\\/\\.\\s]?/; var string = 'this does not belong here 01 2345 6789'; alert(string.match(phoneRegex)); As you can see, ...
🌐
GitHub
gist.github.com › jengle-dev › a327f2b58e08f384ec41dbb5e5454c28
RegEx Phone Number Matching & Validation · GitHub
Share Copy sharable link for this gist. Clone via HTTPS Clone using the web URL. ... 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):
🌐
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
The Phone Number Regex JavaScript Validator lets you instantly check if a number string follows a valid phone number format using JavaScript regex. It’s ideal for use in contact forms, signup flows, or any web app that captures phone inputs. Use this alongside our JavaScript Regex Tester ...
Rating: 4.9 ​ - ​ 60 votes
🌐
Kevinleary
kevinleary.net › blog › validating-real-phone-numbers-javascript
Kevinleary.net: JavaScript Phone Number Validation: Regex & libphonenumber-js
December 8, 2024 - Here are few approaches I’ve used for validating phone numbers with JavaScript, as well as an overview of the best one: libphonenumber-js. The simplest way to validate a phone number is to check for digits, with optional country codes or delimiters. 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); }
🌐
AbstractAPI
abstractapi.com › api guides, tips & tricks › javascript phone number validation
JavaScript Phone Number Validation | Abstract API
1 month ago - Always validate phone numbers on the server before storing or using them. ... Or use a JavaScript masking library like cleave.js. But use masks carefully—they can frustrate users if done wrong or if international input is required. ... Include extension numbers (+1 555 1234 ext. 99) ... Make your validation and error messaging resilient and forgiving. Don’t just say “Invalid number”—guide the user toward fixing it. ... Use regex or a library to validate the format and an API (like AbstractAPI) to check if the number actually exists and is reachable.
🌐
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 - I'm going to leave that one for the reader (hint: use the pipe operator: (...|...)). Now let's take our regex and turn it into a regular expression in javaScript. To do that you just add /.../ around it.
🌐
Trestle
trestleiq.com › home › product › phone validation regex: the what, how, and pros and cons
Phone Validation Regex: The What, How, and Pros and Cons
September 24, 2025 - While regex patterns can become complex to develop and implement for specific validation types, they are typically very reliable. Additionally, they can be implemented in several different programming languages, such as Javascript, Python, and Java. In Python, you can use the “re” module to work with regular expressions. Here’s how you might use it to check if a string matches the specified phone number ...
🌐
RegExr
regexr.com › 3c53v
Phone Number regex
Supports JavaScript & PHP/PCRE RegEx. Results update in real-time as you type. Roll over a match or expression for details.
🌐
Scaler
scaler.com › home › topics › mobile number validation in javascript
Mobile Number Validation Program in JavaScript - Scaler Topics
November 13, 2022 - The "Javascript Regex" refers to the regular expressions in Javascript. The regular expression is a sequence of characters that is used to specify a search pattern in a text. The text is searched with the pattern specified through regular expressions. These regular expressions are used to perform certain "find" or "find and replace" operations on a string or for input validation. For validating a phone number ...