May 2009
Intermediate to advanced
510 pages
15h
English
You need a regular expression that matches a U.K. postcode.
^[A-Z]{1,2}[0-9R][0-9A-Z]?●[0-9][ABD-HJLNP-UW-Z]{2}$| Regex options: None |
| Regex flavors: .NET, Java, JavaScript, PCRE, Perl, Python, Ruby |
Postal codes in the U.K. (or postcodes, as they’re called) are composed of five to seven alphanumeric characters separated by a space. The rules covering which characters can appear at particular positions are rather complicated and fraught with exceptions. This regular expression sticks to the basic rules.
British Standard BS7666, available at http://www.govtalk.gov.uk/gdsc/html/frames/PostCode.htm, describes the U.K. postcode rules.
Read now
Unlock full access