Duncan's blog

October 30, 2008

UK Postcode validation

While looking at some old code at work that was doing postcode validation, I thought there must be a better way to do it with a regular expression. By chance I came across this page, UK Government Data Standards Catalogue, which documents the standard for Post Codes. They also have this XML document which basically gives the regex required.

I was going to submit it to the CFLib, but discovered there was already a IsZIPUK function which ostensibly did the same thing, dating back to about 2001! However its regular expression didn’t validate all postcodes correctly. So I submitted this as an update to that function, which has now been published.

The regular expression’s a bit of a mess, I’m no regex master, so if anyone has any tips on how to simplify it, let me know.

Advertisements

Leave a Comment »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Create a free website or blog at WordPress.com.

%d bloggers like this: