/********************************* form_validation.js for EA.com code excerpts from // Form Validation Functions v1.1.8 // documentation: http://www.dithered.com/javascript/form_validation/index.html // license: http://creativecommons.org/licenses/by/1.0/ // code by Chris Nott (chris[at]dithered[dot]com) *********************************/ /******************************* STORE LOCATOR ******************************/ function validateStoreLocatior(locatorForm,errorDiv) { if(isValidPostalOrZipCode(locatorForm.sZip.value)) { var sLoc = "http://ea.links.channelintelligence.com/Pages/StoreStock.asp?" sLoc += "sZip=" + locatorForm.sZip.value; sLoc += "&sSKU=" + locatorForm.sSKU.value; sLoc += "&nIID=" + locatorForm.nIID.value; sLoc += "&nRadius=" + locatorForm.nRadius.value; sLoc += "&nRGID=" + locatorForm.nRGID.value; sLoc += "&nRID=" + locatorForm.nRID.value; sLoc += "&sCT=" + locatorForm.sCT.value; sLoc += "&nPGID=" + locatorForm.nPGID.value; sLoc += "&sCountry=" + locatorForm.sCountry.value; sLoc += "&sCDATA=" + locatorForm.sCDATA.value; openCenteredWindow(sLoc, "sLoc", 810, 500, false, true, "", ""); getElm(errorDiv).style.display = "none"; getElm("storelocator").style.display = "none"; return false; }else{ getElm(errorDiv).style.display = "block"; return false; } } // Check that an email address is valid based on RFC 821 (?) function isValidEmail(address) { if (address != '' && address.search) { if (address.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1) return true; else return false; } // allow empty strings to return true - screen these with either a 'required' test or a 'length' test else return true; } // Check that an email address has the form something@something.something // This is a stricter standard than RFC 821 (?) which allows addresses like postmaster@localhost function isValidEmailStrict(address) { if (isValidEmail(address) == false) return false; var domain = address.substring(address.indexOf('@') + 1); if (domain.indexOf('.') == -1) return false; if (domain.indexOf('.') == 0 || domain.indexOf('.') == domain.length - 1) return false; return true; } // Remove all spaces from a string function removeSpaces(string) { var newString = ''; for (var i = 0; i < string.length; i++) { if (string.charAt(i) != ' ') newString += string.charAt(i); } return newString; } // Check that a US zip code is valid function isValidZipcode(zipcode) { zipcode = removeSpaces(zipcode); if (!(zipcode.length == 5 || zipcode.length == 9 || zipcode.length == 10)) return false; if ((zipcode.length == 5 || zipcode.length == 9) && !isNumeric(zipcode)) return false; if (zipcode.length == 10 && zipcode.search && zipcode.search(/^\d{5}-\d{4}$/) == -1) return false; return true; } // Check that a Canadian postal code is valid function isValidPostalcode(postalcode) { if (postalcode.search) { postalcode = removeSpaces(postalcode); if (postalcode.length == 6 && postalcode.search(/^[a-zA-Z]\d[a-zA-Z]\d[a-zA-Z]\d$/) != -1) return true; else if (postalcode.length == 7 && postalcode.search(/^[a-zA-Z]\d[a-zA-Z]-\d[a-zA-Z]\d$/) != -1) return true; else return false; } return true; } // Check that it is either a ZIP or Postal Code function isValidPostalOrZipCode(code) { if(isValidZipcode(code) || isValidPostalcode(code)) { return true; }else{ return false; } } // Check that a string contains only letters and numbers function isAlphanumeric(string, ignoreWhiteSpace) { if (string.search) { if ((ignoreWhiteSpace && string.search(/[^\w\s]/) != -1) || (!ignoreWhiteSpace && string.search(/\W/) != -1)) return false; } return true; } // Check that a string contains only letters function isAlphabetic(string, ignoreWhiteSpace) { if (string.search) { if ((ignoreWhiteSpace && string.search(/[^a-zA-Z\s]/) != -1) || (!ignoreWhiteSpace && string.search(/[^a-zA-Z]/) != -1)) return false; } return true; } // Check that a string contains only numbers function isNumeric(string, ignoreWhiteSpace) { if (string.search) { if ((ignoreWhiteSpace && string.search(/[^\d\s]/) != -1) || (!ignoreWhiteSpace && string.search(/\D/) != -1)) return false; } return true; }