I'm sure it's simple and I just don't see it. I've been searching for examples and as short and simple as they are, I can't seem to find my issue.
I wish to validate a Postal Code field and use the Canadian Postal code format. I found an expression I wish to use and it looks like the following:
var validZIP={
"US":"^\d{5}([\-]?\d{4})?$",
"UK":"^(GIR|[A-Z]\d[A-Z\d]??|[A-Z]{2}\d[A-Z\d]??)[ ]??(\d[A-Z]{2})$",
"CA":"^([ABCEGHJKLMNPRSTVXY]\d[ABCEGHJKLMNPRSTVWXYZ])\ {0,1}(\d[ABCEGHJKLMNPRSTVWXYZ]\d)$"
}
Please note the CA which stands for CAnada in this case.
My onChange function calls the following method (onchange class checkValidPostal(this) from the input):
function checkValidPostal(input)
{
var re = new RegExp(validZIP["CA"]);
var value = input.value.toUpperCase();
if (value.match(re))
{
input.value = value;
return true;
}
input.value = "";
return false;
}
I have checked the RegEx line using:
http://www.regular-expressions.info/javascriptexample.html and it works great on that page, but for some reason I can't get it to work on mine!
Please help.
matchand nottest?re.test(value)because it would give me an error that the object^([ABCEGH...doesn't have a functiontest