Regular Expressions 101

Community Patterns

UK Postcode Validation

-1

Regular Expression
ECMAScript (JavaScript)

/
\b(GIR ?0AA|(?:[A-PR-UWYZ](?:\d{0,2}|[A-HK-Y]\d|[A-HK-Y]\d\d|\d[A-HJKSTUW]|[A-HK-Y]\d[ABEHMNPRV-Y])) ?\d[ABD-HJLNP-UW-Z]{2})\b
/
gmi

Description

Matches all valid, current UK Postcodes, including Girobank and non-geographic postcodes, irrespective of whether they contain a space. It does not include overseas territories. Adapted from the BS7666 postcode rules at http://www.cabinetoffice.gov.uk/govtalk/schemasstandards/e-gif/datastandards/address/postcode.aspx

Submitted by Ti Marner - 9 years ago