/* FORM VALIDATION STRING CONSTANTS */ var ErrorMsg = new Object(); ErrorMsg.EMTPY_ENTRY=" field is required."; ErrorMsg.INVALID_EMAIL = "You must enter a valid Email Address."; ErrorMsg.INVALID_SSN = "Please correct your Social Security Number."; ErrorMsg.INVALID1_PHONE_1="Please enter a valid area code"; ErrorMsg.INVALID2_PHONE_1="The area code can only contain numbers"; ErrorMsg.INVALID3_PHONE_1="The area code cannot start with 0 or 1."; ErrorMsg.INVALID1_PHONE_2="Please enter the first three digits of your phone number."; ErrorMsg.INVALID2_PHONE_2="The first three digits of your phone number can contain only numbers. "; ErrorMsg.INVALID1_PHONE_3="Please enter the last four digits of your phone number."; ErrorMsg.INVALID2_PHONE_3="The last four digits of your phone number can only contain numbers"; ErrorMsg.INVALID1_PHONE="Please enter a valid 10 digit phone number with area code first"; ErrorMsg.INVALID2_PHONE="The phone number can only contain numbers."; ErrorMsg.INVALID3_PHONE="The Phone number cannot start with a 0 or a 1."; ErrorMsg.INVALID1_SSN_1="Please enter the first three digits of your ssn."; ErrorMsg.INVALID2_SSN_1="Please enter only numbers for the first part of your ssn."; ErrorMsg.INVALID1_SSN_2="Please enter the middle two digits of your ssn."; ErrorMsg.INVALID2_SSN_2="Please enter only numbers for the middle part of your ssn."; ErrorMsg.INVALID1_SSN_3="Please enter the last four digits of your ssn."; ErrorMsg.INVALID2_SSN_3="Please enter only numbers for the last part of your ssn."; ErrorMsg.INVALID1_SSN="Please enter a valid ssn."; ErrorMsg.INVALID2_SSN="Please enter only numbers in the ssn field."; ErrorMsg.INVALID1_DOB_MM="Please enter only numbers in the date of birth's month field. Please use the mm-dd-yyyy format."; ErrorMsg.INVALID2_DOB_MM="Please enter a valid number in the date of birth's month field"; ErrorMsg.INVALID1_DOB_DD="Please enter only numbers in the date of birth's day field. Please use the mm-dd-yyyy format."; ErrorMsg.INVALID2_DOB_DD="Please enter a valid number in the date of birth's day field"; ErrorMsg.INVALID1_DOB_YY="Please enter only numbers in the date of birth's year field."; ErrorMsg.INVALID2_DOB_YY="Please enter a valid number in the date of birth's year field. Please use the mm-dd-yyyy format."; //Legacy stuff starts function validateComparison(hInput, strCompare, inputDescription, extraDescription) { if (hInput.value != strCompare) { return validationAlert("Please re-enter " + inputDescription + " " + extraDescription + ".", hInput); } return true; } function validatePrematchNPAInput(hInput) { if (hInput.value.length == 0) { return validationAlert(ErrorMsg.EMPTY_PREMATCH_NPA, hInput); } if (hInput.value.length < 3) { return validationAlert(ErrorMsg.INVALID_PREMATCH_NPA, hInput); } if (!isValidPhoneNPA(hInput.value)) { return validationAlert(ErrorMsg.INVALID_PREMATCH_NPA, hInput); } if ((hInput.value == "800") || (hInput.value == "888")) { return validationAlert(ErrorMsg.RESTRICTED_PREMATCH_NPA, hInput); } return true; } function validatePropZipCodeInput(hInput) { if (hInput.value.length == 0) { return true; } if (hInput.value.length < 5) { return validationAlert(ErrorMsg.INVALID_ZIPCODE, hInput); } if (/[^0-9]/.test(hInput.value)) { return validationAlert(ErrorMsg.INVALID2_ZIPCODE, hInput); } return true; } function validateSecondaryPhoneInput(hInput) { if (hInput.value.length == 0) { return true; } if (!isValidEntirePhone(hInput.value)) { return validationAlert(ErrorMsg.INVALID_SEC_PHONE, hInput); } return true; } //Legacy stuff ends ///Following are the functions used in the current validation structure function validationAlert(strAlert, hField) { // Displays an alert, focuses a form field, and returns false. alert(strAlert); try { hField.focus(); } catch(ex) {} return false; } function validatePhone1Input(formPhone1) { if (formPhone1.value.length < 3) { return validationAlert(ErrorMsg.INVALID1_PHONE_1, formPhone1);} if (/[^0-9]/.test(formPhone1.value)) { return validationAlert(ErrorMsg.INVALID2_PHONE_1, formPhone1); } if (/^[01]/.test(formPhone1.value)) { return validationAlert(ErrorMsg.INVALID3_PHONE_1, formPhone1); } if ("200,222,300,333,400,444,500,555,600,666,700,777,900,999".indexOf(formPhone1.value) != -1) { return validationAlert(ErrorMsg.INVALID1_PHONE_1, formPhone1); } return true; } function validatePhone2Input(formPhone2) { if (formPhone2.value.length < 3) { return validationAlert(ErrorMsg.INVALID1_PHONE_2, formPhone2);} if (/[^0-9]/.test(formPhone2.value)) { return validationAlert(ErrorMsg.INVALID2_PHONE_2, formPhone2);} return true; } function validatePhone3Input(formPhone3) { if (formPhone3.value.length < 4) { return validationAlert(ErrorMsg.INVALID1_PHONE_3, formPhone3);} if (/[^0-9]/.test(formPhone3.value)) { return validationAlert(ErrorMsg.INVALID2_PHONE_3, formPhone3); } return true; } function validatePhoneInput(element,formPhone) { if (formPhone.length != 10) { return validationAlert(ErrorMsg.INVALID1_PHONE, element);} if (/[^0-9]/.test((formPhone))) { return validationAlert(ErrorMsg.INVALID2_PHONE, element); } if (/^[01]/.test((formPhone))) { return validationAlert(ErrorMsg.INVALID3_PHONE, element); } return true; } function validateEmail(strEmail) { var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/ if (strEmail.length < 5) { return false; } if (!strEmail.match(re)) { return false; } return true; } function validateSelectbox(hSelectbox, strAlert) { if (hSelectbox.value.length == 0) { return validationAlert(strAlert, hSelectbox); } return true; } function validateSSN1Input(hInput) { if (hInput.value.length != 3) { return validationAlert(ErrorMsg.INVALID1_SSN_1, hInput); } if (/[^0-9]/.test(hInput.value)) { return validationAlert(ErrorMsg.INVALID2_SSN_1, hInput); } return true; } function validateSSN2Input(hInput) { if (hInput.value.length != 2) { return validationAlert(ErrorMsg.INVALID1_SSN_2, hInput); } if (/[^0-9]/.test(hInput.value)) { return validationAlert(ErrorMsg.INVALID2_SSN_2, hInput); } return true; } function validateSSN3Input(hInput) { if (hInput.value.length != 4) { return validationAlert(ErrorMsg.INVALID1_SSN_3, hInput); } if (/[^0-9]/.test(hInput.value)) { return validationAlert(ErrorMsg.INVALID2_SSN_3, hInput); } return true; } function validateSSNInput(hInput){ if (hInput.value.length != 9) { return validationAlert(ErrorMsg.INVALID1_SSN, hInput); } if (/[^0-9]/.test(hInput.value)) { return validationAlert(ErrorMsg.INVALID2_SSN, hInput); } return true; } function validateStringOnly(hInput){ var bal=hInput.value.replace(/[A-Za-z -]/g,""); if (bal.length >=1 ) { return false; } return true; } function validateNumbersWithDashes(hInput){ var bal=hInput.value.replace(/[0-9 -]/g,""); if (bal.length >=1 ) { return false; } return true; } function validateAlphaNumericFields(value,hInput) { if (value.replace(/[0-9A-Za-z]/g, "").length >= 1) { return false; } return true; } function validateStreetAddress(hInput) { if (hInput.value.length < 3) { return validationAlert("Incomplete street address. Please update the information.",hInput); } if (hInput.value.replace(/[^0-9]/g, "").length < 1) { return validationAlert("Incomplete street address. A street number is required. Please update the information.",hInput); } if (hInput.value.replace(/[^A-Za-z]/g, "").length < 1) { return validationAlert("Incomplee street address. A street name is required. Please update the information.",hInput); } if (hInput.value.replace(/[0-9A-Za-z]/g, "").indexOf(" ")==-1) { return validationAlert("The street address needs to have at least one whitespace",hInput); } if(hInput.value.replace(/[\dA-Za-z\s&,-\.&#/]/g,"").length >1) { return validationAlert("Invalid characters were entered in the address field. Please update your entry",hInput); } return true; } function validateUKAddress(hInput){ if(hInput.value.replace(/[\dA-Za-z\s&,-\.&#/]/g,"").length >1) { return validationAlert("Invalid characters were entered in the address field. Please update your entry",hInput); } if(hInput.value.length < 3) { return validationAlert("Incomplete street address. Please update the information.",hInput); } return true; } function validateUKPostCode(hInput){ var test = hInput.value; var size = test.length; var test = test.toUpperCase(); //Change to uppercase while (test.slice(0,1) == " ") { //Strip leading spaces test = test.substr(1,size-1);size = test.length } while(test.slice(size-1,size)== " "){ //Strip trailing spaces test = test.substr(0,size-1);size = test.length } hInput.value = test; //write back to form field if (size < 5 || size > 7){ //Code length rule var count1 = test.indexOf(" ");var count2 = test.lastIndexOf(" "); if (count1 != count2){//only one space rule return validationAlert("Post code must contain one space.", hInput); } else if (count1 == -1 && count2 == -1){ return validationAlert("Post code must contain one space", hInput); } else if ((count1 == count2) &&(count1 !=-1 && count2 !=-1)){ if(size < 6 || size > 8) { return validationAlert("Post code is too short or too long.", hInput); } } } if (!(isNaN(test.charAt(0)))){ //leftmost character must be alpha character rule return validationAlert("Not a valid post code format.", hInput); } if (isNaN(test.charAt(size-3))){ //first character of inward code must be numeric rule return validationAlert("Not a valid post code format.", hInput); } if (!(isNaN(test.charAt(size-2)))){ //second character of inward code must be alpha rule return validationAlert("Not a valid post code format.", hInput); } if (!(isNaN(test.charAt(size-1)))){ //third character of inward code must be alpha rule return validationAlert("Not a valid post code format.", hInput); } return true; } function validateUKPhone(hInput){ if(hInput.value.length < 10){return validationAlert("The phone number is too short. Please update your entry. ",hInput);} if(!validateNumbersOnly(hInput)){return validationAlert("The phone number can only contains digits. Please update your entry.",hInput);} return true; } function validatedob1Input(hInput){ if (hInput.value.length > 12) { return validationAlert(ErrorMsg.INVALID2_DOB_MM,hInput); } if (!validateNumbersOnly(hInput)) { return validationAlert(ErrorMsg.INVALID1_DOB_MM,hInput); } return true; } function validatedob2Input(hInput){ if (hInput.value.length > 31) { return validationAlert(ErrorMsg.INVALID2_DOB_DD,hInput); } if (!validateNumbersOnly(hInput)) { return validationAlert(ErrorMsg.INVALID1_DOB_DD,hInput); } return true; } function validatedob3Input(hInput){ var d = new Date(); if (hInput.value.length > d.getFullYear()) { return validationAlert(ErrorMsg.INVALID2_DOB_YY,hInput); } if (!validateNumbersOnly(hInput)) { return validationAlert(ErrorMsg.INVALID1_DOB_YY,hInput); } return true; } function isEmpty(hInput){ if (hInput.value.length == 0) { return true; } else { return false; } } function validateNumbersOnly(hInput) { if (hInput.value.replace(/[0-9]/g, "").length >=1) { return false; } return true; } function validateCheckbox(hInput, strAlert) { if (!hInput.checked) { return validationAlert(strAlert, hInput); } return true; } function showLightbox(objLink) { // do nothing; // placeholder for lightbox integration; // do not remove; } function validateForm(form){ var fieldName; /* validate only the fields defined in the form */ for (var i=0; i < form.elements.length; i++) { fieldName = form.elements[i].name.toUpperCase(); if ((fieldName == "CC_DEBT_AMT" || fieldName.search("CC_DEBT_AMT")> -1) && form.elements[i].type != "hidden" && true) { if (!validateSelectbox(form.elements[i], "Please select the Credit card debt amount?.")) { return false; } } if ((fieldName == "CC_DEBT_PYMT_AGING" || fieldName.search("CC_DEBT_PYMT_AGING")> -1) && form.elements[i].type != "hidden" && true) { if (!validateSelectbox(form.elements[i], "Please select the Payment status on your credit cards?.")) { return false; } } if ((fieldName == "FNAME" || fieldName.search("FNAME")> -1) && form.elements[i].type != "hidden" && true) { if(isEmpty(form.elements[i]) || !validateStringOnly(form.elements[i])) { return validationAlert("Your First Name may only contain letters, hyphens, or spaces. Please update your entry.",form.elements[i]); } } if ((fieldName == "LNAME" || fieldName.search("LNAME")> -1) && form.elements[i].type != "hidden" && true) { if(isEmpty(form.elements[i]) || !validateStringOnly(form.elements[i])) { return validationAlert("Your Last Name may only contain letters, hyphens, or spaces. Please update your entry.",form.elements[i]); } } if ((fieldName == "STATE" || fieldName.search("STATE")> -1) && form.elements[i].type != "hidden" && true) { if (!validateSelectbox(form.elements[i], "Please select the State.")) { return false; } } if ((fieldName == "ZIP" || fieldName.search("ZIP")> -1) && form.elements[i].type != "hidden" && true) { if(!validateNumbersOnly(form.elements[i])) { return validationAlert("Your Zip can only contain numbers. Please update your entry", form.elements[i]); } else if(isEmpty(form.elements[i])) { return validationAlert("Please enter a zip code, it is a required field.", form.elements[i]); } else if(form.elements[i].value.length > 5) { return validationAlert("Please enter only the first five digits of the zip code."); } } if ((fieldName == "EMAIL" || fieldName.search("EMAIL")> -1) && form.elements[i].type != "hidden" && true) { if(isEmpty(form.elements[i])) { return validationAlert("Please enter a email address, it is a required field. ", form.elements[i]); } else if(!validateEmail(form.elements[i].value)) { return validationAlert("Please enter a valid email address. ", form.elements[i]); } } if ((fieldName == "PRI_PHONE" || fieldName.search("PRI_PHONE")> -1) && form.elements[i].type != "hidden" && true) { if (validatePhone1Input(form.elements[i]) && validatePhone2Input(form.elements[i+1]) && validatePhone3Input(form.elements[i+2])) { } else { return false; } i=i+2; } } showLightbox(this); return true; }