[Gllug] OT: Police Web Site

John Winters john at sinodun.org.uk
Thu Feb 3 13:27:25 UTC 2011


On Thu, 03 Feb 2011 04:04:12 +0000, "general_email at technicalbloke.com"
<general_email at technicalbloke.com> wrote:
[snip]
> Also, normalising a UK postcode is easy, validating it can be a little
> more complicated...
> 
> ^(GIR
>
0AA)|(((A[BL]|B[ABDHLNRSTX]?|C[ABFHMORTVW]|D[ADEGHLNTY]|E[HNX]?|F[KY]|G[LUY]?|H[ADGPRSUX]|I[GMPV]|JE|K[ATWY]|L[ADELNSU]?|M[EKL]?|N[EGNPRW]?|O[LX]|P[AEHLOR]|R[GHM]|S[AEGKLMNOPRSTY]?|T[ADFNQRSW]|UB|W[ADFNRSV]|YO|ZE)[1-9]?[0-9]|((E|N|NW|SE|SW|W)1|EC[1-4]|WC[12])[A-HJKMNPR-Y]|(SW|W)([2-9]|[1-9][0-9])|EC[1-9][0-9])
> [0-9][ABD-HJLNP-UW-Z]{2})$

I've performed a simpler (but still useful) validation in the past by
stripping spaces, turning all letters to X and all numbers to N, and then
comparing it against a list of possible valid results.  There are only
about 5 or 6 of them.

Yes, it doesn't pick up every invalid postcode, but it is still very
useful, because it removes all the total gibberish.

Incidentally, when I last studied the topic, "GIR 0AB" was also a valid
postcode which I don't think the above regex would allow.

Cheers,
John
--
Gllug mailing list  -  Gllug at gllug.org.uk
http://lists.gllug.org.uk/mailman/listinfo/gllug




More information about the GLLUG mailing list