I need a code that says:
If the country is Canada and the zip code is not [letter][number][letter][space][number][letter][number] (e.g., G3H 6A3), then the zip code is wrong.
Here's what I have:
$pattern_canada = "/^[A-Z]\d[A-Z] ?\d[A-Z]\d$";
if (@$_POST['Country'] == "CANADA" && !ereg($pattern_canada, $_POST['Zip'])) {
$message[] = "<li>You must enter a valid Zip Code</li>";
... but it's not working. I've also tried:
$pattern_canada = "[A-Z]\d[A-Z] ?\d[A-Z]\d$";
$pattern_canada = "[A-Z][0-9][A-Z][]?[0-9][A-Z][0-9]$";
$pattern_canada = "[A-Z][0-9][A-Z]\s?[0-9][A-Z][0-9]$";
... and just about every combination of these options as I could think of. But it's still telling me that G3H 6A3 is an invalid Canadian Zip Code.
Can anyone tell me what I'm doing wrong here?
Thanks.