Title |
Test
Find
Pattern Title
|
Expression |
^[A-Z]{1,2}[1-9][0-9]?[A-Z]? [0-9][A-Z]{2,}|GIR 0AA$ |
Description |
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) |
Matches |
G1 1AA | GIR 0AA | SW1 1ZZ |
Non-Matches |
BT01 3RT | G111 1AA |
Author |
Rating:
Not yet rated.
Peter Whyte
|
Source |
Revision of Dave Sparks's version (http://www.regexlib.com/REDetails.aspx?regexp_id=38) |
Your Rating |
|
Title: Not very good
Name: Howard
Date: 4/16/2005 6:48:09 AM
Comment:
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
Comment:
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