Numbers & Finance · In-Browser Regular Expression Lab
US Phone Regex — Match (555) 555-5555, 555-555-5555, and 10 Digits
Flexible US phone number validator matching standard parentheses, hyphens, and spaces.
Flags:
//none
Match Found
Load Sample:
Match Inspection & Details1 match
Match #1:(555) 234-5678
Test Samples Verification Matrix
Expected Valid Samples (Should Match)
(555) 234-5678 Pass
555-234-5678 Pass
+1 555 234 5678 Pass
5552345678 Pass
Expected Invalid Samples (Must Reject)
123-456-7890 Rejected (Pass)
555-012-3456 Rejected (Pass)
555-5555 Rejected (Pass)
Code Implementation Generator
// JavaScript / TypeScript (ES6+)
const pattern = /^(?:\+?1\s*(?:[.-]\s*)?)?(?:\(\s*([2-9]1[02-9]|[2-9][02-8]1|[2-9][02-8][02-9])\s*\)|([2-9]1[02-9]|[2-9][02-8]1|[2-9][02-8][02-9]))\s*(?:[.-]\s*)?([2-9]1[02-9]|[2-9][02-9]1|[2-9][02-9]{2})\s*(?:[.-]\s*)?([0-9]{4})$/;
const text = "(555) 234-5678";
const isMatch = pattern.test(text);
console.log("Is Match:", isMatch);
if (isMatch) {
const matches = text.match(pattern);
console.log("Matches:", matches);
}Regular Expression Token Breakdown
Validates North American Numbering Plan (NANP) rules with area code and exchange restrictions. Each component of the regular expression serves a distinct syntactical purpose as mapped below:
| Token Pattern | Name / Component | Function & Rule |
|---|---|---|
| (?:\+?1\s*)? | Optional Country Code | Optional +1 prefix for North America. |
| \(\s*...\s*\) | Area Code | 3-digit area code with optional parentheses. |
| [.-]? | Delimiters | Optional dash, dot, or space separators. |
| [0-9]{4}$ | Line Number | Final 4-digit station number. |
Frequently Asked Questions
Why are area codes starting with 0 or 1 invalid?
Related Regular Expressions
Browse All 40 PatternsNumbers & Finance
International Phone (E.164)
Matches international standard phone numbers starting with a plus sign and 7 to 15 digits.
/^\+[1-9]\d{1,14}$/Test regex
Numbers & Finance
IBAN Bank Account Matcher
Validates canonical IBAN structure: 2-letter country code, 2-digit checksum, and up to 30 alphanumeric characters.
/^[A-Z]{2}[0-9]{2}[A-Z0-9]{4}[0-9]{7}([A-Z0-9]?){0,16}$/Test regex
Numbers & Finance
Credit Card (Visa & Mastercard)
Detects Visa and Mastercard credit card format with optional space or hyphen delimiters.
/^(?:4[0-9]{12}(?:[0-9]{3})?|5[1-5][0-9]{14}|2(?:22[1-9]|2[3-9][0-9]|[3-6][0-9]{2}|7[01][0-9]|720)[0-9]{12})$/Test regex