Christian Bennett

Navigation

Skip navigation.

Search

Site navigation

Email conversation

FromChristian Bennett
ToMe
SubjectUK postal address Validation
Date22 July 2005 04:41
Hi!

I'm having trouble validating UK postal addresses. I
was wondering if you had a script that could that or
could explain how the UK postal system works in order
for me to develop one of my own.
FromMe
ToChristian Bennett
SubjectRe: UK postal address Validation
Date25 July 2005 16:23
Christian,

> I'm having trouble validating UK postal addresses. I
> was wondering if you had a script that could that or
> could explain how the UK postal system works in order
> for me to develop one of my own.

I do not know of any script for this, since addresses are generally very
hard to get a full pattern.

To my knowledge, there is:
Optional Recipient name
Optional flat number
A house number & street name OR a house name and optional street name.
Optional Village/town/district
Optional major town/district
Postal district (postal county - not in line with voting counties)
Optional province
Postal code
Optional country (UK)

The most basic address is

45
NP7 9TJ

or

Hope house
NP7 9TJ

However, generally, you would also expect a postal district as well, and
road name if only a house number is used instead of a name.

Hope house
Gwent
NP7 9TJ

The format of UK post codes is (as far as I know)
[a-z]{2}\d{1,2}\s+\d{1,2}[a-z]{2}

Normally, I would say:
[Address line 1 - essential]
[Address line 2 - optional ]
[Address line 3 - optional ]
[Address line 4 - optional ]
[Post district  - essential]
[Province       - optional ]
[Post code      - essential]

Address line 1 and post district must not be empty, Post code must match
the regex I gave above.

Mark 'Tarquin' Wilton-Jones - author of http://www.howtocreate.co.uk/
This site was created by Mark "Tarquin" Wilton-Jones.
Don't click this link unless you want to be banned from our site.