|
Posted by Toby Inkster on 11/28/06 15:33
GreyWyvern wrote:
> And lo, Toby Inkster didst speak in alt.html,alt.php,alt.www.webmaster:
>
>> For what it's worth, I've written a PHP library that validates and
>> canonically formats (people in the UK will know how important that is!)
>> postcodes for the following countries:
>>
>> - Canada
>
> Can it handle H0H 0H0 ?
Yes -- the parsing for non-UK postcodes is far more rudimentry than for UK
postcodes. For Canada it just uses the following regular expression on a
normalised (all uppercase, with whitespace collapsed) postcode to check
the format is OK:
/^[A-CEGHJ-NPRSTV-Z][0-9][A-CEGHJ-NPRSTV-Z]\s+[0-9][A-CEGHJ-NPRSTV-Z][0-9]$/
Regular expressions for non-UK countries are here:
http://examples.tobyinkster.co.uk/postcodes/data/intlpc.txt
Columns are:
- ISO 2-character country code, lower case
- PCRE for valid postcodes
- optional country prefix for certain European countries
(the PCRE should match the country-prefixed postcode)
--
Toby A Inkster BSc (Hons) ARCS
Contact Me ~ http://tobyinkster.co.uk/contact
Navigation:
[Reply to this message]
|