Hi,
You can probably find some interesting stuff in the sub-packages of PEAR::Validate
(it's in PHP) that correspond to the locales you want
For instance, in the Validate_US
class :
function postalCode($postalCode, $strong = false)
{
return (bool)preg_match('/^[0-9]{5}((-| )[0-9]{4})?$/', $postalCode);
}
The same method, in the Validate_FR
class :
function postalCode($postalCode, $strong = false)
{
return (bool) preg_match('/^(0[1-9]|[1-9][0-9])[0-9][0-9][0-9]$/',
$postalCode);
}
But note that this kind of regex will only allow you to validate that an given code looks valid, not that it actually is valid : there are so many postal codes (and even more addresses !), the list would be un-manageable, and a maintenance nightmare, I guess.