T
ToolPrime

Regex for Phone Number (US)

Validates US phone numbers in various formats: (555) 123-4567, 555-123-4567, 5551234567.

Pattern

/^\(?[2-9]\d{2}\)?[-.\s]?\d{3}[-.\s]?\d{4}$/

Live Tester

Enter a string to test

Examples

(555) 123-4567
555-123-4567
5551234567
(055) 123-4567
123-4567
555-1234-567

Pattern Breakdown

^\(?[2-9]\d{2}\)? — area code with optional parentheses

[-.\s]? — optional separator

\d{3} — exchange code (3 digits)

[-.\s]?\d{4}$ — separator + subscriber number (4 digits)

Code Snippets

Javascript

const regex = /^\(?[2-9]\d{2}\)?[-.\s]?\d{3}[-.\s]?\d{4}$/;
regex.test("(555) 123-4567"); // true

Python

import re
pattern = r"^\(?[2-9]\d{2}\)?[-.\s]?\d{3}[-.\s]?\d{4}$"
bool(re.match(pattern, "(555) 123-4567"))  # True

Php

$pattern = '/^\(?[2-9]\d{2}\)?[-.\s]?\d{3}[-.\s]?\d{4}$/';
preg_match($pattern, "(555) 123-4567"); // 1

Related Patterns