Regex for phone numbers
8 Mar 2026
Phone numbers in the US and Canada consist of ten digits: a three-digit area code, a three-digit central office code, and a four-digit line number. These components may be separated by dashes, spaces, or dots; the area code is often written in parentheses:
619-555-0167 (619) 555-0167 619.555.0167
There are some limits on the area code:
- the area code cannot start with 0 or 1 (these digits are used for long-distance calls);
- the N11 codes are used for special services (most people remember 911 for emergencies);
- 988 is a suicide crisis helpline.
Taking these restrictions into account, we can put together this regular expression to match a 10-digit US phone number:
^[ \t]*\(?(?!988)[2-9](?!11)\d\d\)?[ .-]?\d{3}[ .-]?\d{4}[ \t]*$
We use a negative lookahead here to skip the N11 codes and 988, so this regex is a bit more fool-proof than other solutions floating on the Internet. For example, it won't match 123-456-7890 or 911-123-4567.
The [ \t]* part skips optional whitespace before or after the phone number. The regex starts with ^ and ends with $, so it will match the whole string or a line (in multi-line mode). If you want to find phone numbers in the text rather than verify that the string is a phone number, please use \b to match word boundaries:
\b\(?(?!988)[2-9](?!11)\d\d\)?[ .-]?\d{3}[ .-]?\d{4}\b
Another useful addition to this regex is allowing the initial +1 or 1 for long-distance calling:
^[ \t]*(?:\+1 ?|1 ?)?\(?(?!988)[2-9](?!11)\d\d\)?[ .-]?\d{3}[ .-]?\d{4}[ \t]*$
Now the regex also matches:
+1 619-555-0167 +16195550167 1 619-555-0167
International phone numbers consist of a plus sign, a country code (1 to 3 digits), and the national phone number. The total phone number length is limited to a maximum of 15 digits. The minimum length is not specified in the standard, but I found Niue, an island country with a three-digit country code and four-digit national numbers. Five digits are more common, see Tokelau, Tonga, Solomon Islands, or Vanuatu. This gives us the following regex:
^[ \t]*\+(?:\d\)?[ .-]?\(?){6,14}\d[ \t]*$
We first match the plus sign, then a digit. After each digit, there can be a closing parenthesis, then a space, dot, or dash, then an opening parenthesis. The last digit is matched separately; the total number of digits is from 7 to 15.
Restricting the phone number length for each country would be complicated and the numbering plans change sometimes, so I recommend allowing some freedom here.
The regular expressions above also don't try to balance parentheses; for example, +1 (214 555-0198 would match, but this is rarely a problem.
Finally, if you want to match either an international phone number or a US/Canadian number, you can combine both regexes:
^[ \t]*(?:(?:\+|011 ?)(\d\)?[ .-]?\(?){6,14}\d|\(?(?!988)[2-9](?!11)\d\d\)?[ .-]?\d{3}[ .-]?\d{4})[ \t]*$
In this combined regex, we also allow international phone numbers to start with 011 instead of the plus.
Stop pasting your data into dubious cloud-based tools. Aba Search and Replace is your Swiss army knife for regular expression search, fast and safe updates across multiple files, and various conversions, with all your data staying on your computer. Built for power users, developers, testers, and analysts. Hand-coded in the EU.
This is a blog about Aba Search and Replace, a tool for replacing text in multiple files.
- Regex for phone numbers
- On coding with LLMs
- When msvc::musttail attribute silently fails
- Mnemonics for hidden controls
- Unix and JavaScript timestamps
- Replace only the Nth match
- Aba 2.8 released
- Anonymizing a dataset by replacing names with counters
- Automatically add width and height to img tags
- Using zero-width assertions in regular expressions
- Aba 2.7 released
- Regular Expressions 101
- 2023 in review
- Regular expression for numbers
- Aba 2.6 released
- Search from the Windows command prompt
- Empty character class in JavaScript regexes
- Privacy Policy Update - December 2022
- Aba 2.5 released
- Check VAT ID with regular expressions and VIES
- Which special characters must be escaped in regular expressions?
- Aba 2.4 released
- Privacy Policy Update - April 2021
- Review of Aba Search and Replace with video
- Aba 2.2 released
- Discount on Aba Search and Replace
- Using search and replace to rename a method
- Cleaning the output of a converter
- Aba 2.1 released
- How to replace HTML tags using regular expressions
- Video trailer for Aba
- Aba 2.0 released
