REGEXVAULTv2.0
Localization/Phone Numbers
Verified Safe

US/Canada Phone Number (NANP) Regex for JavaScript

/^(?:\+1[\s.-]?)?(?:\(([2-9][0-9]{2})\)|([2-9][0-9]{2}))[\s.-]?([2-9][0-9]{2})[\s.-]?([0-9]{4})$/

What this pattern does

This page provides a comprehensive, battle-tested regular expression for matching us/canada phone number (nanp), ported and verified for JavaScript. A rigorously tested regex reduces debugging time and protects your application from edge-case failures. The snippet below is ready to drop into your JavaScript project — whether you're validating in an Express middleware, a Next.js API route, or a client-side form.

Javascript Implementation

Javascript
// US/Canada Phone Number (NANP)
// ReDoS-safe | RegexVault — Localization > Phone Numbers

const uscanadaPhoneNumberNanpRegex = /^(?:\+1[\s.-]?)?(?:\(([2-9][0-9]{2})\)|([2-9][0-9]{2}))[\s.-]?([2-9][0-9]{2})[\s.-]?([0-9]{4})$/;

function validateUscanadaPhoneNumberNanp(input: string): boolean {
  return uscanadaPhoneNumberNanpRegex.test(input);
}

// Example
console.log(validateUscanadaPhoneNumberNanp("+1 212-555-0100")); // true

Test Cases

Matches (Valid)
Rejects (Invalid)
+1 212-555-0100112-555-0100
212-555-0100212-055-0100
(212) 555-0100212-555-010
212.555.0100+44 212-555-0100
2125550100800-1234567

When to use this pattern

This pattern is drawn from the Localization > Phone Numbers category and carries a ReDoS-safe certification. That matters for JavaScript developers because especially critical in long-running Node.js event loops where a ReDoS vulnerability can block the entire process. RegexVault audits patterns against known backtracking attack vectors, ensuring you have the necessary context before using this regex in a high-stakes production environment.

Common Pitfalls

Canada shares the +1 country code with the US. Area codes do not reliably indicate country — some Canadian area codes (e.g., 416=Toronto) look identical to US codes in format.

Technical Notes

NANP area codes and exchange codes cannot start with 0 or 1. Capture groups: 1/2=area code, 3=exchange, 4=subscriber. 555-0100 through 555-0199 are reserved for fiction. Toll-free: 800, 888, 877, 866, 855, 844, 833.

Have a pattern that belongs in the vault?

Submit it for review — community-verified patterns get credited to your GitHub handle. Free submissions join the queue. Priority review available for $15.

Submit a Pattern