Phone Number Regex: Validate Phone Numbers
Use these phone number regex patterns to validate digits only, common formatted numbers, and international numbers, with JavaScript, Python, and HTML examples.
Use these phone number regex patterns to validate phone numbers in forms and apps. Below you will find practical patterns for digits-only, formatted, and international numbers, plus copy-ready examples for JavaScript, Python, and HTML.
Phone number regex
There is no single perfect regex for every phone number format. Start by deciding whether you need digits only, a flexible user-input format, or an international number with a leading +.
Digits-only regex:
^\d+$
Flexible phone number regex:
^\+?[\d\s\-()]+$
International-style regex:
^\+[1-9]\d{1,14}$What the flexible regex matches:
- 1234567890
- +1 555 123 4567
- (555) 123-4567
- +44 20 7946 0958
What it does not match:
- abc1234567
- 555-EXT-99
- ++1 555 123 4567
Quick note: If you need production-grade international validation, regex alone is usually not enough. Use regex for format checks and a phone parsing library for full validation.
The basic international phone number validation
A simple regex to validate string against a valid international phone number format without delimiters and with an optional plus sign:
True
False
Enter a text in the input above to see the result
Example code in Javascript
The more complex phone number validation
This regular expression will match phone numbers entered with delimiters (spaces, dots, brackets, etc.)
True
False
Enter a text in the input above to see the result
Example code in Javascript
Common mistakes
1. Expecting one regex to cover every country and format
Phone numbers vary a lot by country, length, separators, and local conventions. A short regex can help with format validation, but it cannot fully understand all real phone number rules.
2. Using digits-only validation when users type formatted numbers
If your users enter values like:
- +1 555 123 4567
- (555) 123-4567
- 020 7946 0958
then a digits-only regex will reject valid user input.
3. Treating regex as real phone verification
Regex does not tell you whether:
- the country code is valid
- the number is assigned
- the number can receive SMS or calls
If you need that, use a parsing or verification service.
4. Mixing validation and normalization
These are different goals:
- validation checks whether the input format is acceptable
- normalization converts the input into a standard format such as E.164
Usually you need both.
True
False
Enter a text in the input above to see the result
Extra information about validating phone number
While validation of phone numbers using regex can give a possibility to check the format of the phone number, it does not guarantee that the number exists.
There might be also an option to leave a phone number field without any validation since some users might have:
- More complex phone numbers with extensions
- The different phone numbers for calling them on a different time of day
