On Apr 7, 4:07 pm, Graeme <[email protected]> wrote:
> Hi there,
> I've recently had to change a function that validates UK postcodes
> (via pattern matching) because we found it was not accurate with a lot
> of crazy London postcodes. I changed the function to be a little more
> leniant in the hope that if it APPEARS like a UK postcode then Google
> Maps would slap us and tell us it was incorrect when we sent it off to
> get the coordinates.

Geocoding ZZ8 4DT,UK yields a result in Pune, India. I have no idea
why. I suppose you *could* verify that if a 200 result is returned,
its location is actually within the UK; or use JSON or XML and verify
that the CountryNameCode is GB. But if all you're doing is postcode
verification with no use for a map, then you shouldn't be using
Google's services anyway: the TOS require the results to be displayed
on a map.

So this is the wrong approach. You should make your pattern-matching
accurate if you want to verify UK postcodes. A search for "pattern-
match uk postcode" yields a first result 
http://regexlib.com/REDetails.aspx?regexp_id=260
which seems to be exactly what's required.

Except that it only validates the format, so E20 postcodes will be
valid; and it won't work with UK postcodes for the Falklands or
Pitcairn (FIQQ 1ZZ and PCRN 1ZZ) and the like -- but you might not
want to include those as London postcodes anyway.

It could be enhanced so that only the 124 postal areas are valid,
which would cut out ZZ and FF; or if you're only interested in London,
then you could check for the 129 postal districts explicitly before
simply checking the format of the inbound portion.

The only sure-fire way of validating a UK postcode is via the paid
services of the Royal Mail. Getting a pattern-match right is a good
start, though.

Andrew
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Google Maps API" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/Google-Maps-API?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to