Article written

  • on 20.05.2009
  • at 08:19 AM
  • by arkin

UK Postcode Regular Expression 2

May20

Here is a UK postcode matching regular expression. I built it using a database of all the UK postcodes, so it does work for the strange ones.

This regular expression will match the first part:

^[A-Z]{1,2}[0-9]{1,2}[A-Z]?$

It will allow: B1, LN8, EC2M.
It will not allow: 123, 1LL, N123.

This regular expression should match the entire postcode:

^[A-Z]{1,2}[0-9]{1,2}[A-Z]? [0-9]{1,2}[A-Z]{1,3}$

It will allow: B1 7AB, LN8 12AR, EC2M 9CD.
It will not allow: 123 123, 1LL 123, N123 ASD.

Hope you find these as useful as I did.

subscribe to comments RSS

There are 2 comments for this post

  1. cool stuff says:

    Am gonna use this expresions

    Thanks

Please, feel free to post your own comment

* these are required fields

arkinEx Codex is powered by WordPress and FREEmium Theme.
developed by Dariusz Siedlecki and brought to you by FreebiesDock.com