[thelist] UK Postcode Validation

Lee kowalkowski lee.kowalkowski at googlemail.com
Thu Aug 24 08:56:52 CDT 2006


On 24/08/06, Chris Dempsey <evolt at cubeit.co.uk> wrote:
> Hi,
>
> Can anyone point me to a UK Postcode validation script?  Prefer it not to be
> javascript but if it's easily configurable this would do.  Currently all
> other error checking on this particular form is done server side with
> vbScript
>
For the validation rules, you can download the PAF Digest from
http://www.royalmail.com/portal/rm/content1?catId=400085&mediaId=1400098
(see Chapter 2 - Structure of a Postcode).

The following expression is based on an old copy of the digest I have
lying around from December 03.  I'm not able to download the latest
PDF file at the moment.

/^([a-z]{1,2}\d[a-z1-9]? ?\d[abd-hjlnp-vw-z]{2}|GIR ?0AA)$/i

If you want to force entry of the space between the Outcode and
Incode, remove the question marks that follow spaces (but not the
first).

The following expression is taken from the Royal Mail's website itself
(by doing a javascript:alert(validPostcode) on their PAF sample data
order entry page), it's more relaxed, it allows the invalid format
AANNA NAA, and doesn't allow Alliance & Leicester Girobank's postcode,
GIR 0AA, so I've no idea how they'll ever get their hands on a copy!

/^[A-Z]{1,2}[\d]{1,2}([A-Z])?\s?[\d][A-Z]{2}$/i

-- 
LK



More information about the thelist mailing list