UK Phone Number Regex for JavaScript
/^(?:\+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 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
// UK Phone Number
// ReDoS-safe | RegexVault — Localization > Phone Numbers
const ukPhoneNumberRegex = /^(?:\+44|0)(?:\s|-)?(?:[1-9][0-9]{1,4})(?:\s|-)?(?:[0-9]{3,4})(?:\s|-)?(?:[0-9]{3,4})$/;
function validateUkPhoneNumber(input: string): boolean {
return ukPhoneNumberRegex.test(input);
}
// Example
console.log(validateUkPhoneNumber("+44 20 7946 0958")); // trueTest 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 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
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