Monday, 28 May 2012

How to Validate a UK Postcode using JavaScript


Here's a great link for the RegEx that is needed to validate a UK postcode using JavaScript.

In case the link doesn't work, here it is:

var regPostcode = /^([a-zA-Z]){1}([0-9][0-9]|[0-9]|[a-zA-Z][0-9][a-zA-Z]|[a-zA-Z][0-9][0-9]|[a-zA-Z][0-9]){1}([ ])([0-9][a-zA-z][a-zA-z]){1}$/;

The accepted formats are:
A9 9AA
A99 9AA
AA9 9AA 
AA99 9AA 
AA9A 9AA

No comments:

Post a Comment