Regular Expressions 101

Community Patterns

UK Postcode Checker

3

Regular Expression
PCRE (PHP <7.3)

/
^([a-zA-Z]{1,2}\d{1,2}[a-zA-Z]{0,2})\s*?(\d[a-zA-Z]{2})$
/
gmi

Description

This is an improvement of the very good tH9mQ1/1. It did not pickup on the first two postcodes found here: //http://en.wikipedia.org/wiki/Postcodes_in_the_United_Kingdom

Submitted by Flexander - 9 years ago