function validateZip( vField, vEdits ) { // Author: Mark Thompson, Univar USA. // Purpose: Test if ZIP code not null, contains numbers and has either 5 or 9 numbers. Reformat //with a dash if 9 numbers detected. (i.e. nnnnn-nnnn). Return false and message if ZIP is invalid. // Subroutines used: alertBox, strip_chars var zip_str = strip_chars(vField.value, " -_"); var zip_len = zip_str.length; var errormessage = "Please enter a valid ZIP Code. ZIP Code should be either 5 or 9 digits."; if (vEdits != null) { if ( (vEdits.indexOf("nr") > -1) || (vEdits.indexOf("NR") > -1) ) { if (zip_str == "") { vField.value = ""; return true; } } } if ((zip_len != 9) && (zip_len != 5 )) { alertBox (vField, errormessage, "text"); return false; } else { for (var j = 0; j < zip_len; j++) { var ch = zip_str.substring(j, j+1); if ((ch < "0") || (ch > "9")) { alertBox (vField, errormessage, "text"); return false; } } } if (zip_len == 9) { vField.value = zip_str.substring(0,5) + "-" + zip_str.substring(5,9); } else { vField.value = zip_str; } return true; // ends the function validateZip } function ValidateZip( vField, vEdits ) { return validateZip( vField, vEdits ); } function validateZIP( vField, vEdits ) { return validateZip( vField, vEdits ); }