UK Postcode RegEx

Recently I needed to validate UK postcodes for a site I was building, after a bit of hunting around this seemed to be the best one that I could find, hopefully this will save me some Googling in future!


^([Gg][Ii][Rr] 0[Aa]{2})|((([A-Za-z][0-9]{1,2})|(([A-Za-z][A-Ha-hJ-Yj-y][0-9]{1,2})|(([A-Za-z][0-9][A-Za-z])|([A-Za-z][A-Ha-hJ-Yj-y][0-9]?[A-Za-z]))))\s?[0-9][A-Za-z]{2})$
Categories: Programming

Leave a Reply

Your email address will not be published. Required fields are marked *