Validating UK Phone Numbers: Formats, Ofcom Ranges and the Mistakes Every Regex Makes

Validation · November 2026 · 10 min read

Area codes are two to five digits, the prefix tells you the type, and most validators get both wrong. The rules, a classifier you can paste, seven common mistakes, E.164 storage, and the Ofcom drama ranges to use in test data.

Most UK phone number validation is a regular expression written by someone who remembered their own number and generalised from it. UK numbers are more varied than that: area codes are two to five digits long, local numbers are correspondingly shorter, and the prefix tells you whether a number is a landline, a mobile, freephone or premium rate. This guide gives the rules, a validator that follows them, the mistakes every quick regex makes, and the numbers to use in test data so that a test run can never call a real person.

The shape of a UK number

A UK telephone number is ten or eleven digits after the leading zero is dropped, with 0 written in front for national dialling and +44 in front for international dialling. The leading zero is a trunk prefix, not part of the number, which is why 020 7946 0123 and +44 20 7946 0123 are the same number.

Below the leading zero, the first digit sets the type:

Ofcom publishes the full allocation as the National Telephone Numbering Plan, and it is the only authoritative source for which ranges are live. The structure is covered in more depth in the UK telephone numbering plan explained.

Area codes are not a fixed length

This is the fact that breaks most validators. Geographic area codes are two, three, four or five digits after the zero, and the local number shrinks to match so the total stays at ten (occasionally nine) digits:

So there is no 0207: London's code is 020, and a local number beginning with 7 follows it. Writing 0207 946 0123 is not wrong as a dialling string, but a validator that treats 0207 as the area code will reject 020 3xxx xxxx numbers, which have existed since 2005, and will mis-split the number for display. The UK dialling code lookup returns the correct area code and its length for any town.

A validator that follows the rules

The practical approach is: normalise to digits, then check the national-format number against the structural rules by prefix. Full accuracy needs Ofcom's allocation data, which changes; a structural check covers almost everything a form needs.


function normaliseUkNumber(input) {
  let digits = input.replace(/[\s().-]/g, '');
  if (digits.startsWith('+44')) digits = '0' + digits.slice(3);
  else if (digits.startsWith('0044')) digits = '0' + digits.slice(4);
  else if (digits.startsWith('44') && digits.length === 12) digits = '0' + digits.slice(2);
  return digits;
}

function classifyUkNumber(input) {
  const n = normaliseUkNumber(input);
  if (!/^0\d{9,10}$/.test(n)) return { valid: false, reason: 'UK numbers are 10 or 11 digits including the leading 0' };
  if (/^07[1-9]\d{8}$/.test(n)) return { valid: true, type: 'mobile', e164: '+44' + n.slice(1) };
  if (/^070\d{8}$/.test(n)) return { valid: true, type: 'personal-number', e164: '+44' + n.slice(1) };
  if (/^0[12]\d{8,9}$/.test(n)) return { valid: true, type: 'geographic', e164: '+44' + n.slice(1) };
  if (/^03\d{8}$/.test(n)) return { valid: true, type: 'non-geographic', e164: '+44' + n.slice(1) };
  if (/^080\d{7,8}$/.test(n)) return { valid: true, type: 'freephone', e164: '+44' + n.slice(1) };
  if (/^08[47]\d{8}$/.test(n)) return { valid: true, type: 'special-rate', e164: '+44' + n.slice(1) };
  if (/^09\d{8}$/.test(n)) return { valid: true, type: 'premium-rate', e164: '+44' + n.slice(1) };
  if (/^05[56]\d{8}$/.test(n)) return { valid: true, type: 'corporate-or-voip', e164: '+44' + n.slice(1) };
  return { valid: false, reason: 'Not a recognised UK number range' };
}

classifyUkNumber('020 7946 0123');   // geographic, +442079460123
classifyUkNumber('+44 7700 900123'); // mobile, +447700900123
classifyUkNumber('0207 946 0123');   // geographic (same number, badly spaced)
classifyUkNumber('0906 123 4567');   // premium-rate: a consumer form may want to reject this

Which types to accept is a product decision. A delivery contact number should accept geographic and mobile and probably 03, and reject premium rate. An SMS verification flow should accept mobile only. A business contact field might accept everything but 09.

The mistakes every quick regex makes

1. Assuming a fixed split, such as ^0\d{3} \d{3} \d{4}$. Rejects London, Cardiff, Northern Ireland and every five-digit area code. 2. Requiring spaces, or forbidding them. Users type numbers however they like. Strip spaces, dots, brackets and dashes before checking. 3. Rejecting +44. International format is the one you should store. Accept it, and accept the 0044 and bare 44 forms people paste from contact lists. 4. Keeping the leading 0 after +44. +44 (0)20 7946 0123 is a human convention; +44020... is not a dialable number. Drop the zero when converting. 5. Treating all 07 numbers as mobiles. 070 is personal numbering (often expensive to call) and 076 is largely pagers. If "mobile" matters, check for 07[1-9]. 6. Treating 03 as premium rate. It is charged at the same rate as 01 and 02 and is used by government departments and charities. Blocking it blocks legitimate contact numbers. 7. Validating that the number is in service. A regex cannot do this. Only a live lookup (an HLR query for mobiles, or a carrier service) says whether a number is active, and that costs money and raises data protection questions.

How to store and display

Store E.164: +442079460123, +447700900123. It is unambiguous, sortable, and what every telephony and SMS API expects. Keep the user's original input if you want to redisplay it exactly, and otherwise format on display using the correct area code split, which needs a lookup table of area code lengths. Never store with spaces, and never store as a number, since leading zeros and the plus sign are lost.

Phone numbers in test data

Generating a UK number from a real area code and random digits regularly produces a live number. When a test run sends an SMS or places a call to it, a member of the public is contacted, which is a complaint at best and a regulatory problem at worst.

Ofcom reserves specific blocks for drama and fiction, so that numbers shown on television never reach a subscriber. They are exactly right for test data, and they are the only numbers the UK phone number generator produces:

A test suite built on these ranges exercises every type a validator distinguishes (two-digit and three-digit area codes, mobile, freephone, premium rate) without any possibility of contacting anyone. Pair them with fictional people and addresses from the test data generator, and use the REST API to pull them into seed scripts.

Related reading

For the structure behind the ranges, see the UK telephone numbering plan explained. For the same "validate the structure, verify with the authority" pattern applied to other fields on a UK form, see the guides to checking a UK address, UK bank account numbers and National Insurance numbers.

More guides