Displaying page
of
pages;
Items to
Title |
Test
Details
Pattern Title
|
Expression |
^([A-PR-UWYZ0-9][A-HK-Y0-9][AEHMNPRTVXY0-9]?[ABEHMNPRVWXY0-9]? {1,2}[0-9][ABD-HJLN-UW-Z]{2}|GIR 0AA)$
|
Description |
Regular expression to match valid UK postcodes.
In the UK postal system not all letters are used in all positions (the same with vehicle registration plates) and there are various rules to govern this. This regex takes into account those rules.
Details of the rules:
First half of postcode
Valid formats
[A-Z][A-Z][0-9][A-Z]
[A-Z][A-Z][0-9][0-9]
[A-Z][0-9][0-9]
[A-Z][A-Z][0-9]
[A-Z][A-Z][A-Z]
[A-Z][0-9][A-Z]
[A-Z][0-9]
Exceptions
Position - First.
Contraint - QVX not used
Position - Second.
Contraint - IJZ not used except in GIR 0AA
Position - Third.
Constraint - AEHMNPRTVXY only used
Position - Forth.
Contraint - ABEHMNPRVWXY
Second half of postcode
Valid formats
[0-9][A-Z][A-Z]
Exceptions
Position - Second and Third.
Contraint - CIKMOV not used
|
Matches |
DN3 6GB | SW42 4RG | GIR 0AA
|
Non-Matches |
SEW4 5TY | AA2C 4FG | AA2 4CV
|
Author |
Rating:
Not yet rated.
Stuart Wade
|
Displaying page
of
pages;
Items to