UK postcode validation

  • Thread starter Thread starter Mike P
  • Start date Start date
M

Mike P

Can anybody tell me what are the valid formats for UK postcodes? As far
as I am aware postcodes can be 6-7 characters long (excluding spaces)
and the first part of the postcode can be 3-4 chars long and the second
part can only be 3 chars long. Am I missing any other valid formats?
 
Mike said:
Can anybody tell me what are the valid formats for UK postcodes? As far
as I am aware postcodes can be 6-7 characters long (excluding spaces)
and the first part of the postcode can be 3-4 chars long and the second
part can only be 3 chars long. Am I missing any other valid formats?

A basic regular expression for UK postcodes would be something like:

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

If that's of any help? It's certainly simpler than trying to explain the
ways in which they can be formatted!

Either way, it will handle codes like:

LL31 9XX
L66 2XU
WC1B 4BB

All of which are valid formats.

--
Dylan Parry
http://electricfreedom.org | http://webpageworkshop.co.uk

The opinions stated above are not necessarily representative of
those of my cats. All opinions expressed are entirely your own.
 
Can anybody tell me what are the valid formats for UK postcodes? As far
as I am aware postcodes can be 6-7 characters long (excluding spaces)
and the first part of the postcode can be 3-4 chars long and the second
part can only be 3 chars long. Am I missing any other valid formats?

*** Sent via Developersdexhttp://www.developersdex.com***

There is a good coverage of this on wikipedia: http://en.wikipedia.org/wiki/UK_postcodes
This entry on the Royal Mail site also explains what area, district,
sector and unit mean so you can get a better idea of the format:
http://www.royalmail.com/portal/rm/...eyname=postcodefinder&catId=28400668#14800240
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top