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.

🌐
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.
Discussions

Phone Number Regular Expression Validation
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 format and validate phone number is nest.js
Create your own custom decorator More on reddit.com
🌐 r/typescript
9
1
September 20, 2023
Telephone Number Validator
Are you sure that’s the correct syntax · Ahhh I see, it runs all the test now but I need to go about this in a different way. It passes all of the ones that should return false and two of the true tests but that doesn’t mean much because I am not accounting for the - or () or spaces · ... More on forum.freecodecamp.org
🌐 forum.freecodecamp.org
0
0
May 29, 2023
Validating phone numbers - worth the trouble?
Do you mean validating just format, or like actually whether it's a valid, working phone number? More on reddit.com
🌐 r/webdev
33
8
February 18, 2022
🌐
npm
npmjs.com › package › libphonenumber-js
libphonenumber-js - npm
2 weeks ago - Imagine a "promo-site" or a "personal website" being deployed once and then running for years without any maintenance, where a client may be unable to submit a simple "Contact Us" form just because this newly-allocated pool of mobile phone numbers wasn't present in that old version of libphonenumber-js that was used when building the website. Whenever there's a "business requirement" to validate phone number input, I prefer using PhoneNumber.isPossible() instead of PhoneNumber.isValid(), so that it just validates the phone number length and doesn't validate the actual phone number digits.
      » npm install libphonenumber-js
    
Published   Mar 13, 2026
Version   1.12.40
Author   catamphetamine
🌐
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.
🌐
Kevinleary
kevinleary.net › blog › validating-real-phone-numbers-javascript
Kevinleary.net: JavaScript Phone Number Validation: Regex & libphonenumber-js
December 8, 2024 - Validate phone numbers in JavaScript using regular expressions and the libphonenumber-js library. This guide covers simple regex, NANP validation, and international numbers.
🌐
Twilio
twilio.com › en-us › blog › validate-phone-number-input
How to Validate Phone Number Input in HTML and ...
April 23, 2025 - If you Googled "phone number regex" and regretted it you're in the right place. This post will walk through how to use two free tools to check a phone number's validity using HTML and JavaScript.
Find elsewhere
🌐
GitHub
github.com › google › libphonenumber
google/libphonenumber: Google's common Java, C++ and ...
Google's common Java, C++ and JavaScript library for parsing, formatting, and validating international phone numbers. - google/libphonenumber
Starred by 17.9K users
Forked by 2.2K users
Languages   C++ 53.4% | Java 29.9% | JavaScript 15.8% | CMake 0.4% | C 0.2% | Closure Templates 0.1%
🌐
UI Bakery
uibakery.io › regex-library › phone-number
Phone number regex
Most important things to know about Phone number regex and examples of validation and extraction of Phone number from a given string in JavaScript programming language.
🌐
AbstractAPI
abstractapi.com › api guides, tips & tricks › javascript phone number validation
JavaScript Phone Number Validation | Abstract API
2 weeks ago - For validating international formats: Use a library like libphonenumber-js. For the most accurate results and enriched data: An API like AbstractAPI's Phone Validation is the best choice.
🌐
Medium
medium.com › @ankitpatidar030 › phone-number-validation-using-google-library-554fe94612ec
Phone Number validation using google library. | by ankit patidar | Medium
March 15, 2024 - For verifying phone number we have a lot of apis and packages available on internet for validating phone number. Here are some of them: 1. AbstractAPI 2. Numverify 3. Numlookup API 4. Neutrino 5. Mocean 6. Vonage 7. BytePlant · But we are not going to work on any of them. Will come to this in next article. Today we will going to look on something which is being provided by google called as libphonenumber-js .
🌐
SitePoint
sitepoint.com › javascript
Phone Number Regular Expression Validation
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, ...
🌐
W3Schools
w3schools.in › javascript › validate-a-phone-number
JavaScript Validate a Phone Number
Learn how to effectively validate 10-digit phone numbers in web forms using JavaScript and HTML with our comprehensive tutorial on JavaScript Phone Number Validation. Discover the practical implementation of regular expressions to ensure accurate and reliable phone number validation.
🌐
W3Schools
w3schools.com › js › js_validation.asp
W3Schools.com
JS Examples JS HTML DOM JS HTML Input JS HTML Objects JS HTML Events JS Browser JS Editor JS Exercises JS Quiz JS Website JS Syllabus JS Study Plan JS Interview Prep JS Bootcamp JS Certificate JS Reference ... HTML form validation can be done by JavaScript.
🌐
Stack Abuse
stackabuse.com › validate-phone-numbers-in-javascript-with-regular-expressions
Validate Phone Numbers in JavaScript with Regular Expressions
June 7, 2023 - Excluding the country code, combining the remaining parts results in a ten-digit phone number where the area code and the telephone prefix are three digits each, and the line number is four digits. Let's now move into writing a JavaScript function that validates a phone number based on these criteria using regular expressions.
🌐
Veriphone
veriphone.io
Phone number validation & carrier lookup | Veriphone
Find a phone number's line-type, carrier and region, whenever available. Validate your phone numbers list in minutes: Upload your CSV, Validate, Download.
🌐
DEV Community
dev.to › rthefounding › checking-if-telephone-number-is-valid-4iop
Validating Phone Numbers with JavaScript - DEV Community
September 2, 2021 - // 6. $ end of the string function numberCheck(str) { const regex = /^(1\s?)?(\d{3}|\(\d{3}\))[\s\-]?\d{3}[\s\-]?\d{4}$/ return regex.test(str) } numberCheck("1 555-555-5555"); will display true
🌐
Kevin Chisholm
blog.kevinchisholm.com › javascript › javascript-e164-phone-number-validation
Javascript E164 Phone Number Validation | Kevin Chisholm - Blog
February 10, 2021 - The easiest way to perform JavaScript E164 phone number validation is with an ordinary function that contains a regular expression and a test statement. We’ll call our function validatePhoneForE164 and it will pass a variable named phoneNumber ...
🌐
Reddit
reddit.com › r/typescript › how to format and validate phone number is nest.js
r/typescript on Reddit: How to format and validate phone number is nest.js
September 20, 2023 -

Greetings!

How would I go around validation, parsing and formatting phone numbers in nest.js?

I intend to send SMS authenticationcodes to users for registration and I want to save their phone number in my database.

What is the go to method for this?

I have tried the IsPhoneNumber decorator but i am having mixed feelings about it because it allows phone numbers such as:

"+16505553434aaassfddfhdj" To pass the validation.

I don t want to have that text at all and i m not sure that just stripping the letters is enough.

Please provide some advice!

🌐
Intl-tel-input
intl-tel-input.com
International Telephone Input
A JavaScript plugin for entering, formatting and validating international telephone numbers. Includes React, Vue, Angular and Svelte components.
🌐
freeCodeCamp
forum.freecodecamp.org › javascript
Telephone Number Validator
May 29, 2023 - function telephoneCheck(str) { // A phone number must have 10 digits or 11 digits if the first number is a 1 for (let i = 0; i < str.length; i++) { if (str[i] > "0" && str[i] <= "9" && str.length() == 10 || str[i] >…