![[personal profile]](https://www.dreamwidth.org/img/silk/identity/user.png)
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:
- The letters [QVX] are not used in the first position.
- The letters [IJZ] are not used in the second position.
- The only letters to appear in the third position are [ABCDEFGHJKSTUW].
- The only letters to appear in the fourth position are [ABEHMNPRVWXY].
- 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.
no subject
Date: 2008-08-27 18:45 (UTC)no subject
Date: 2008-08-27 19:43 (UTC)no subject
Date: 2008-08-27 19:45 (UTC)no subject
Date: 2008-08-27 19:14 (UTC)no subject
Date: 2008-08-27 21:02 (UTC)no subject
Date: 2008-08-27 23:11 (UTC)no subject
Date: 2008-08-27 23:14 (UTC)no subject
Date: 2008-08-27 23:31 (UTC)Where is that, then?
no subject
Date: 2008-08-27 23:35 (UTC)The '0AA' is zero-A-A so does fit the NAA scheme.
no subject
Date: 2008-08-28 03:58 (UTC)These conventions may change in the future if operationally required.
So these aren't rules that Royal Mail follow, just a description of the current state.
no subject
Date: 2008-08-28 08:31 (UTC)no subject
Date: 2008-08-28 09:10 (UTC)If you're only handling full postcodes, since the incode is always NAA, the space is an optional convention. If, on the other hand, your software is expected to understand town-only, town+sector (outcode) and town+sector+district (? it's a couple of years since I was doing this—I can't remember all the terminology) as well, it's essential to distinguish AANN from AAN N.
no subject
Date: 2008-08-28 17:45 (UTC)no subject
Date: 2008-08-28 12:54 (UTC)However this was only chat in a bar from a coursemate, so I don't know how true it is.
no subject
Date: 2008-08-28 19:47 (UTC)I remember being impressed, a decade ago, to hear that they
computer sort letters by post code whilst the letters are moving at 40mph !