Regular Expressions 101

Community Patterns

Community Library Entry

0

Regular Expression
ECMAScript (JavaScript)

/
^([a-z]{1,2}[a-z0-9]{1,2})\s*?(\d[a-z]{2})$
/
gmi

Description

Checks for valid UK/British postcodes.

A modified version of MaffooBristol's pattern that prevents a non-whitespace character being entered in between the two sections of the postcode.

Works in PHP/JS

Doesn't take into account character exclusions for each position

Submitted by anonymous - 8 years ago