REGEXVAULTv2.0
Localization/Phone Numbers
Verified Safe

US/Canada Phone Number (NANP) Regex for PHP

/^(?:\+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 PHP. A rigorously tested regex reduces debugging time and protects your application from edge-case failures. The snippet below is ready to drop into your PHP project — whether you're validating in a Laravel validator, a WordPress plugin, or a standalone PHP script.

Php Implementation

Php
<?php
// US/Canada Phone Number (NANP)
// ReDoS-safe | RegexVault — Localization > Phone Numbers

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

function validate_uscanada_phone_number_nanp(string $input): bool {
    return (bool) preg_match(USCANADA_PHONE_NUMBER_NANP_PATTERN, $input);
}

// Example
var_dump(validate_uscanada_phone_number_nanp("+1 212-555-0100")); // bool(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 PHP developers because especially relevant in PHP where PCRE backtracking limits can trigger silent failures on malicious input. 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