Regular Expressions 101

Community Patterns

Community Library Entry

0

Regular Expression
Created·2016-07-29 09:48
Flavor·JavaScript

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

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