Contact
UK Phone Number Regex
UK numbers start with a trunk 0 when dialled domestically or with +44 internationally, followed by nine or ten more digits depending on the area. This pattern accepts both prefixes and allows single spaces anywhere between digits, so it handles common layouts such as 020 7946 0018, 07700 900123 and +44 20 7946 0123. It is useful for UK contact forms, delivery checkouts and CRM imports. The honest limit is that it does not know which area codes or number ranges are actually allocated, so it accepts some numbers that could never be dialled.
Pattern (JavaScript)
/^(?:\+44 ?|0)[1-9](?: ?[0-9]){8,9}$/Starts at the start of the line/string, then (the text "+44", then a space, optionally (zero or one time) OR the character "0"), then one of the characters 1-9, then (a space, optionally (zero or one time), then a digit), between 8 and 9 times, then the end of the line/string.
Limit: Checks the format only; it cannot tell whether the number is allocated or in service.
Examples
Matches
- ✓ 020 7946 0018
- ✓ +44 20 7946 0123
- ✓ 07700 900123
Does not match
- ✗ 0044 20 7946 0123
- ✗ 020 794
- ✗ +1 415 555 0100
Try it
0 matches (JavaScript engine)
020 7946 0018
+44 20 7946 0123
07700 900123
0044 20 7946 0123
020 794
+1 415 555 0100Code in 8 languages
Converted automatically from the JavaScript pattern; language-specific notes are shown where the syntax or support differs.
JavaScript
const re = /^(?:\+44 ?|0)[1-9](?: ?[0-9]){8,9}$/g;
const text = "020 7946 0018";
const matches = [...text.matchAll(re)].map((m) => m[0]);
console.log(matches);Python
import re
pattern = re.compile(r'^(?:\+44 ?|0)[1-9](?: ?[0-9]){8,9}$')
text = '020 7946 0018'
matches = [m.group(0) for m in pattern.finditer(text)]
print(matches)PHP
<?php
$pattern = '/^(?:\+44 ?|0)[1-9](?: ?[0-9]){8,9}$/';
$text = '020 7946 0018';
preg_match_all($pattern, $text, $matches);
print_r($matches[0]);Java
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Main {
public static void main(String[] args) {
Pattern pattern = Pattern.compile("^(?:\\+44 ?|0)[1-9](?: ?[0-9]){8,9}$");
String text = "020 7946 0018";
Matcher matcher = pattern.matcher(text);
while (matcher.find()) {
System.out.println(matcher.group());
}
}
}Go
package main
import (
"fmt"
"regexp"
)
func main() {
re := regexp.MustCompile(`^(?:\+44 ?|0)[1-9](?: ?[0-9]){8,9}$`)
text := "020 7946 0018"
fmt.Println(re.FindAllString(text, -1))
}C#
using System;
using System.Text.RegularExpressions;
var pattern = new Regex(@"^(?:\+44 ?|0)[1-9](?: ?[0-9]){8,9}$");
var text = "020 7946 0018";
foreach (Match m in pattern.Matches(text))
{
Console.WriteLine(m.Value);
}Rust
// Cargo.toml: regex = "1"
use regex::Regex;
fn main() {
let re = Regex::new(r"^(?:\+44 ?|0)[1-9](?: ?[0-9]){8,9}$").unwrap();
let text = "020 7946 0018";
for m in re.find_iter(text) {
println!("{}", m.as_str());
}
}- Add regex = "1" under [dependencies] in Cargo.toml.
Ruby
pattern = /^(?:\+44 ?|0)[1-9](?: ?[0-9]){8,9}$/
text = '020 7946 0018'
matches = text.to_enum(:scan, pattern).map { Regexp.last_match[0] }
p matchesFrequently asked questions
- Why is +44 0 20 not accepted?
- When the +44 country code is used, the trunk 0 must be dropped. The pattern requires a digit from 1 to 9 straight after the prefix, which rejects the common mistake of keeping the zero.
- Are dashes or brackets allowed?
- No, only spaces are allowed between digits. Remove dashes and brackets before testing, or extend the separator class to [ -] if you want to accept dashes.
- Which numbers are safe to use in examples?
- Ofcom reserves ranges such as 020 7946 0000 to 0999 and 07700 900000 to 900999 for drama and examples. Using them avoids publishing anyone's real number.