The official Postcode Specification states that a valid UK postcode conforms to the following rules:
- The letters Q, V and X are not used in the first position.
- The letters I, J and Z are not used in the second position.
- The only letters to appear in the third position are A, B, C, D, E, F, G, H, J, K, S, T, U and W.
- The only letters to appear in the fourth position are A, B, E, H, M, N, P, R, V, W, X and Y.
- The second half of the postcode is always consistent numeric, alpha, alpha format and the letters C, I, K, M, O and V are never used.
Note: These conventions may change in the future if operationally required.
If you want users of your site to supply their postcode, you can ensure that they can only enter a valid one by doing the following.
Add a Single Line Text item and add the following, exactly as shown, to the Parameters box:
^([Gg][Ii][Rr] 0[Aa]{2})|((([A-Za-z][0-9]{1,2})|(([A-Za-z][A-Ha-hJ-Yj-y][0-9]{1,2})|(([A-Za-z][0-9][A-Za-z])|([A-Za-z][A-Ha-hJ-Yj-y][0-9]?[A-Za-z])))) {0,1}[0-9][A-Za-z]{2})$
The above code gives users the option to enter the postcode in either upper or lower case lettering. If you want to force users to enter the postcode in upper-case only, add the following text to the Parameters box:
^(GIR 0[A]{2})|((([A-Z][0-9]{1,2})|(([A-Z][A-HJ-Y][0-9]{1,2})|(([A-Z][0-9][A-Z])|([A-Z][A-HJ-Y][0-9]?[A-Z])))) {0,1}[0-9][A-Z]{2})$
Note: The validation code matches postcodes starting GIR which are for GiroBank.