Here is a simple ASP based function that will check a UK postcode to make sure it is in a valid format - it is based on rules from the Government Data Standards Catalogue - The basic rules are...
- 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.
This does only check that the format is valid, it does not know if the actual data is valid, I would be happy to update this script if any public domain reference data could be provided.
Hopefully it will be helpful to somebody!