fanf: (Default)
[personal profile] fanf

A little contribution for anyone else who searches the web for this in the future.

The UK postcode consists of two parts. The first part is the Outward Postcode, or Outcode. This is separated by a single space from the second part which is the Inward Postcode, or Incode. The Outcode directs mail to the correct local area for delivery. The Incode is used to sort the mail at the local area delivery office.

The Outcode has 6 possible formats (as follows) and the Incode is consistently numeric, alpha, alpha format.

  • AN NAA
  • ANN NAA
  • ANA NAA
  • AAN NAA
  • AANN NAA
  • AANA NAA

There are some restrictions on the letters:

  1. The letters [QVX] are not used in the first position.
  2. The letters [IJZ] are not used in the second position.
  3. The only letters to appear in the third position are [ABCDEFGHJKSTUW].
  4. The only letters to appear in the fourth position are [ABEHMNPRVWXY].
  5. The letters [CIKMOV] are not used in the second part.

This translates into a perl extended regex as follows (with slightly relaxed whitespace):

qr{\b
    ([A-PR-UWYZ]\d[\dA-HJKSTUW]? # rules 1,3
    |[A-PR-UWYZ][A-HK-Y]\d[\dABEHMNPRVWXY]? # rules 1,2,4
    )[\t ]{1,2}
    (\d[ABD-HJLNP-UW-Z]{2}) # rule 5
\b}x

Update: more here.

Date: 2008-08-27 23:14 (UTC)
pm215: (Default)
From: [personal profile] pm215
Also breaks rule 0 in that AAA isn't one of the standard outcode forms.

Date: 2008-08-27 23:31 (UTC)
From: [identity profile] bellinghman.livejournal.com
That's an 'I' for India, not a '1'?

Where is that, then?

Date: 2008-08-27 23:35 (UTC)
From: [identity profile] bugshaw.livejournal.com
It's a rare non-geographic postcode. [EDIT: for Girobank as was, in Bootle]
The '0AA' is zero-A-A so does fit the NAA scheme.

Edited Date: 2008-08-28 00:08 (UTC)

June 2025

S M T W T F S
1234567
8 91011121314
15161718192021
22232425262728
2930     

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Page generated 2025-06-11 06:46
Powered by Dreamwidth Studios