Pattern library / Validation
Phone Number Regex (Intl & US Formats)
Phone numbers have no single shape: +1-415-555-2671, (415) 555-2671 and 0812-3456-7890 are all valid, all different. This pattern accepts an optional country code, optional parentheses and -/./ separators — then the notes give you the strict E.164 and per-country variants when you need them.
^(\+[0-9]{1,3}[-. ]?)?\(?[0-9]{2,4}\)?[-. ]?[0-9]{3,4}([-.\s][0-9]{3,4}){0,2}$
Load this pattern into the tester →
How the pattern works
(\+[0-9]{1,3}[-. ]?)?— optional+and country code (1–3 digits): the part people forget when they paste international numbers into forms.([-.\s][0-9]{3,4}){0,2}— up to two more separator+digit groups; that is what lets one pattern accept both555-2671and3456-7890tails.- Strict E.164 (what SMS gateways want):
^\+[1-9][0-9]{1,14}$— no separators, 2–15 digits total. US-only NANP:^\(?[0-9]{3}\)?[-.\s]?[0-9]{3}[-.\s]?[0-9]{4}$. - This validates shape, not reachability — only a real call or SMS proves a number exists.
Test it: match & no-match examples
Every row is loaded straight into the tester — click Try to see the match live:
| Input | Result | Why | |
|---|---|---|---|
+1-415-555-2671 | Match | country code + NANP with dashes | Try → |
(415) 555-2671 | Match | parentheses around the area code | Try → |
0812-3456-7890 | Match | local format with separators | Try → |
12345 | Match | five digits pass — tighten for production (pitfalls) | Try → |
call me | No match | letters are not digits | Try → |
12-34 | No match | too few digits after the separator | Try → |
Where to use it
JavaScript
const PHONE = /^(\+[0-9]{1,3}[-. ]?)?\(?[0-9]{2,4}\)?[-. ]?[0-9]{3,4}([-.\s][0-9]{3,4}){0,2}$/;
PHONE.test('(415) 555-2671'); // true
Python (normalize to E.164)
import re
def e164(s):
digits = re.sub(r'[^0-9+]', '', s)
return digits if re.fullmatch(r'\+[1-9][0-9]{1,14}', digits) else None
BigQuery / GA4 (RE2)
SELECT REGEXP_CONTAINS(REPLACE(phone, '-', ''), r'^\+[1-9][0-9]{1,14}$')
Common mistakes
- No country context? A bare 7-digit local number can quietly swallow a country-code length — decide whether
+is mandatory before you ship the rule. - Extensions (
x123,ext. 45) are not part of any phone shape — strip them first:s.split(/x|ext/i)[0]. - Shape passes on
12345by design (loose minimum). For forms, add a code-level guard: strip to digits and require 7–15 of them.
FAQ
What is the regex for E.164 phone numbers?
^\+[1-9][0-9]{1,14}$ — plus sign, then 9 to 14 more digits, no separators. Strip spaces, dashes and parentheses before testing.
Why does my regex match 12345?
The digit groups allow short runs on purpose — locale-agnostic patterns cannot know your minimum length. Tighten the groups or validate the digit count in code (7–15).
How do I match US numbers only?
^\(?[0-9]{3}\)?[-.\s]?[0-9]{3}[-.\s]?[0-9]{4}$ — exactly 10 digits with optional parentheses and separators, no country code.
Related patterns
Email Validation Regex — Practical Pattern to Test · Country Code Regex - ISO 3166 Alpha-2 / Alpha-3 · Extract Numbers from String — Regex + Examples
For GA4-specific patterns, see the GA4 regex cheat sheet, the page path regex guide, the event filter regex guide, the GA4 regex match types, the custom channel grouping guide and RE2 vs PCRE. Browse the full regex pattern library.