I used some of the excellent resources from DITHERING.COM for help in my
groveling newbie attempts to cough up working form validation....
I cut and pasted bits of code to check USA ZIP codes and CANADIAN POSTAL
codes, and merged them into one function that I called validCode. The
<form> tag has an onSubmit call to a general form-checker that works fine to
make sure all fields are filled. But within the form is a ZIP/POSTAL CODE
field, where the onBlur calls the function below: "
onBlur="validCode();".... The form-checking works fine, but when the
"onBlur" is engaged, it gives me an "object expected" error where I'm
defining the "var zip".
If any of you seasoned warriors could lend me a neuron or 2, I owe you a
cappuchino or more...
=============================
function validCode(zip) {
var zip = removeSpaces(zip);
if (!(zip.length == 5 || zip.length == 9 || zip.length == 10)) return
false;
if ((zip.length == 5 || zip.length == 9) && !isNumeric(zip)) return
false;
if (zip.length == 10 && zipcode.search && zipcode.search(/^\d{5}-\d{4}$/)
== -1) return false;
return true;
// Check that a Canadian postal code is valid
if (zip.search) {
zip = removeSpaces(zip);
if (zip.length == 6 && zip.search(/^[a-zA-Z]\d[a-zA-Z]\d[a-zA-Z]\d$/)
!= -1) return true;
else if (zip.length == 7 &&
zip.search(/^[a-zA-Z]\d[a-zA-Z]-\d[a-zA-Z]\d$/) != -1) return true;
else return false;
}
return true;
}
// ---> END
</script>
=============================