- The first Regular Expression Library on the Web!

Please support RegExLib Sponsors


Regular Expression Details

Title Test Find Pattern Title
^[A-Z]{1,2}[1-9][0-9]?[A-Z]? [0-9][A-Z]{2,}|GIR 0AA$
Matches UK postcodes according to the following rules 1. LN NLL eg N1 1AA 2. LLN NLL eg SW4 0QL 3. LNN NLL eg M23 4PJ 4. LLNN NLL eg WS14 0JT 5. LLNL NLL eg SW1N 4TB 6. LNL NLL eg W1C 8LQ. Modifications: 1) Doesn't allow leading zeros in first part (outward) eg BT01 3RT is incorrect; it should be BT1 3RT. 2) Only allows uppercase letters, which is the preference of the UK Post Office. 3) Permits the only postcode to break the rules - GIR 0AA (for the old Girobank, now Alliance & Leicester bank, address)
G1 1AA | GIR 0AA | SW1 1ZZ
BT01 3RT | G111 1AA
Author Rating: Not yet rated. Peter Whyte
Source Revision of Dave Sparks's version (
Your Rating
Bad Good

Enter New Comment

Spammers suck - we apologize. Please enter the text shown below to enable your comment (not case sensitive - try as many times as you need to if the first ones are too hard):

Existing User Comments

Title: Not very good
Name: Howard
Date: 4/16/2005 6:48:09 AM
Marginally better than most other examples here, only about 615 slipped through the net as 'valid' from 1423 invalid postcodes.

Title: Extra alpha allowed
Name: Stephen Jones
Date: 12/2/2004 12:13:54 PM
CF14T 3EW passes but it shouldn't because in [A-Z]{1,2}[1-9][0-9]?[A-Z]? [0-9][A-Z]{2,} you have [0-9]?[A-Z]? - i.e. zero or one digit and zero or one alpha

Copyright © 2001-2018, | ASP.NET Tutorials