UK Phone Number Regex for PHP
/^(?:\+44|0)(?:\s|-)?(?:[1-9][0-9]{1,4})(?:\s|-)?(?:[0-9]{3,4})(?:\s|-)?(?:[0-9]{3,4})$/What this pattern does
This page provides a comprehensive, battle-tested regular expression for matching uk 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
// UK Phone Number
// ReDoS-safe | RegexVault — Localization > Phone Numbers
define('UK_PHONE_NUMBER_PATTERN', '/^(?:\+44|0)(?:\s|-)?(?:[1-9][0-9]{1,4})(?:\s|-)?(?:[0-9]{3,4})(?:\s|-)?(?:[0-9]{3,4})$/');
function validate_uk_phone_number(string $input): bool {
return (bool) preg_match(UK_PHONE_NUMBER_PATTERN, $input);
}
// Example
var_dump(validate_uk_phone_number("+44 20 7946 0958")); // bool(true)Test Cases
Matches (Valid) | Rejects (Invalid) |
|---|---|
+44 20 7946 0958 | +1 20 7946 0958 |
020 7946 0958 | 44 20 7946 0958 |
+447911123456 | +44 (0) 20 7946 |
07911 123456 | — |
0800 123 456 | — |
020-7946-095 | — |
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
UK numbers vary in length depending on area code — London has an 8-digit local number, while rural areas may have 7 or even 6. This variability makes regex validation approximate at best.
Technical Notes
UK uses a complex numbering plan. 020 = London, 0161 = Manchester, 07xxx = mobile, 0800 = freephone, 01xxx/02xxx = geographic. The (0) is sometimes shown in international format (+44 (0)20...) but not dialed.
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