1001Ferramentas
๐Ÿ‡ฌ๐Ÿ‡งValidators

UK Postcode Validator

Validate UK postcode (SW1A 1AA pattern).

UK postcode: the alphanumeric outward + inward code

A British postcode is an alphanumeric code of 5 to 7 characters split into two parts separated by a single space: the outward code (e.g. SW1A) that routes the mail to a postal district, and the inward code (e.g. 1AA) that pinpoints a street, side of a street or a single large delivery point. Rolled out nationwide by the Royal Mail between 1959 and 1974, postcodes are maintained in the Postcode Address File (PAF) covering around 1.8 million codes. The validator on this page checks the structural pattern, not membership in PAF.

The format is famously irregular. Valid shapes are A9 9AA, A99 9AA, A9A 9AA, AA9 9AA, AA99 9AA and AA9A 9AA โ€” the outward part is 2โ€“4 characters, the inward part is always one digit followed by two letters. There is no check digit; correctness is structural plus a lookup against PAF.

Anatomy of SW1A 1AA

  • Area (SW): one or two letters, the posttown group (SW = South West London). There are 121 postcode areas.
  • District (1A): the digit(s), optionally with a final letter, identifying the sorting district.
  • Sector (1): first character of the inward code.
  • Unit (AA): last two letters; the final pair never uses C, I, K, M, O or V to avoid OCR confusion.

Where it shows up

  • Address lookup: "enter your postcode" forms expand to a list of houses via PAF โ€” the standard UK checkout flow.
  • Geo & demographics: postcodes map to ONS output areas, used for census, insurance pricing and catchment analysis.
  • Logistics & NHS: delivery routing, GP catchment, council-tax banding all key off the postcode.
  • Mock data / testing: generating format-valid codes for fixtures and form QA.

Gotchas

  • The space matters for humans, not for matching: SW1A1AA and SW1A 1AA are the same code; normalise by inserting a space before the last three characters.
  • Special cases: GIR 0AA (the former Girobank) and overseas-territory codes (BFPO, AI-2640 Anguilla) don't fit the standard regex.
  • Forbidden letters: a strict validator excludes QVX from the first position and other position-specific letter rules โ€” most regexes relax these.
  • Format-valid โ‰  deliverable: only PAF confirms a postcode actually exists and is in use.

FAQ

How many addresses does one postcode cover? On average about 15 properties, but it ranges from a single large building (its own code) to a whole rural hamlet.

Is the space required? Royal Mail recommends it, but matching should be done after stripping/normalising it. The inward code is always the final three characters.

Why are some letters never used? C, I, K, M, O, V are excluded from the final two-letter unit to prevent misreads by hand and by OCR sorting machines.

Related Tools