Brazilian Phone Number Regex for PHP
/^(?:\+55\s?)?(?:\(?([1-9][1-9])\)?\s?)(?!\1\s?9[0-9]{8}$|11\s?987654321$)(?:9[0-9]{4}-[0-9]{4}|[2-9][0-9]{3}-[0-9]{4}|9[0-9]{8}|[2-9][0-9]{7})$/What this pattern does
This page provides a comprehensive, battle-tested regular expression for matching brazilian phone number, 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
// Brazilian Phone Number
// ReDoS-safe | RegexVault — Localization > Phone Numbers
define('BRAZILIAN_PHONE_NUMBER_PATTERN', '/^(?:\+55\s?)?(?:\(?([1-9][1-9])\)?\s?)(?!\1\s?9[0-9]{8}$|11\s?987654321$)(?:9[0-9]{4}-[0-9]{4}|[2-9][0-9]{3}-[0-9]{4}|9[0-9]{8}|[2-9][0-9]{7})$/');
function validate_brazilian_phone_number(string $input): bool {
return (bool) preg_match(BRAZILIAN_PHONE_NUMBER_PATTERN, $input);
}
// Example
var_dump(validate_brazilian_phone_number("+55 11 98765-4321")); // bool(true)Test Cases
Matches (Valid) | Rejects (Invalid) |
|---|---|
+55 11 98765-4321 | +55 01 98765-4321 |
(11) 98765-4321 | 11 12345-6789 |
11987654321 | +55 11 12345-6789 |
+5511912345678 | — |
(21) 3456-7890 | — |
11 987654321 | — |
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
The extra 9 digit for mobiles was added region by region between 2012-2016. Old data may have 8-digit mobile numbers in some DDDs. Validate based on the DDD's transition date for historical data.
Technical Notes
Brazilian DDD codes are 2 digits (11=São Paulo, 21=Rio de Janeiro, etc.). Mobile numbers have 9 digits starting with 9; landlines have 8 digits. +55 is the country code. All mobiles received a 9th digit in 2012-2016.
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