//-----------------------------------//
//	CHECKS VALIDITY OF ZIP CODE FOR US AND CANADA
//	REQUIRES LOADING 'GENERALVALIDATE.JS' BEFORE
//	THIS FILE IN YOUR CALLING PAGE
//	NOTE: THIS IS USUALLY ONLY USED
//	BY COMPANIES WHO ONLY ACCEPT CREDIT CARDS
//	ISSUED BY BANKS IN THE USA OR CANADA
//-----------------------------------//
//-----------------------------------//
//	ASEMBLE ERROR MESSAGE HERE AS IT'S RATHER LENGTHY
//-----------------------------------//
var ZipMsg = "a valid US or Canadian postal code";
ZipMsg += "\nUSA is 5 digits only or 5 digits a dash and 4 digits";
ZipMsg += "\nFor example: '12345' or '12345-1234'";
ZipMsg += "\nCanada is 3 characters a space then 3 characters";
ZipMsg += "\nFor example: '123 LOP'";

var isOkay = true;

//-----------------------------------//
//	YOUR FIELD ARRAY - YOU CAN ADD TO
//	THE ARRAY USED IN PREVIOUS ARTICLES
//	JUST ENSURE YOUR generalValidate.js
//	FILE HAS THIS FUNCTION AND REGEX IN IT
//-----------------------------------//
aFieldList = new Array();
aFieldList[0] = "isZipCode(document.forms[\"form1\"].zip, ZipMsg);"

function checkZip(){
    iLength = aFieldList.length;
    for(i = 0; i < iLength; i++){
        if(isOkay){
            //alert("i = " + i);
            isOkay = eval(aFieldList[i]);
        }
    }
    if(isOkay){
      alert("Form completed!");
      //document.forms["f1"].submit();
    } else {
        isOkay = true;
        return false;
    }
}

