/*****************************************\ || || HTML Form Validation Functions || || _____________________________________ || || Created by: Eric Hemesath - hemesathej || Created on: 09-23-2002 || Last Update: 10-31-2003 || _____________________________________ || || Functions: || chkNull(): Checks for Null Fields || takes(The error message to display,The name of the HTML form,The name of the html form element) || chkNumeric(): Checks for invalid characters in a numeric field. REMOVES %,*,-,#,=,+,$ FROM INPUT || takes(The label of the field,The name of the HTML form,The name of the html form element) || chkZip(): Checks characters and length of zip codes || takes(The name of the HTML form,The name of the html form element) || chkPhone(): Checks characters and length of US phone #s || takes(The name of the HTML form,The name of the html form element) || chkEmail(): Checks for correct email format || takes(The name of the HTML form,The name of the html form element) || chkDate(): Checks for valid date format MUST USE DD-MON-YYYY || takes(The separator you wish to use,The name of the HTML form,The name of the html form element) || chkSpace(): Checks for spaces in desired field || takes(The title of the field,The name of the HTML form,The name of the html form element) || cnfmField(): Checks two HTML form fields to see if they match || takes(The error message to display,The name of the HTML form,The name of the first html form element,The name of the second html form element) || _____________________________________ || || JS FILES THAT CALL THIS FILE: || AdjusterSignup.js || AdjusterProfile.js || AgentSignup.js || AgentProfile.js || Broker.js || Customer.js || LossPayee.js || PolicyLine.js || PolicyholderSignup.js || PolicyholderProfile.js || \*****************************************/ ///------------------------------------------------------------------------------ function chkNull(msg,form,element) { if (document.forms[form].elements[element].value == "") { alert(msg); document.forms[form].elements[element].focus(); return false; } } //------------------------------------------------------------------------------- function chkNumeric (label,form,element) { var num = document.forms[form].elements[element].value; num = num.replace(/[\%\*\-\#\=\+\$\ ]/g, ''); if (isNaN(num)) { alert("The " + label + " field contains invalid characters.\n\nValid Characters: '0-9' ."); document.forms[form].elements[element].value = num; document.forms[form].elements[element].focus(); return false; } else { document.forms[form].elements[element].value = num; } } //------------------------------------------------------------------------------- function chkZip(form,element) { var zip = document.forms[form].elements[element].value; zip = zip.replace(/[\(\)\.\-\ ]/g, ''); if (isNaN(zip)) { alert("The zip code contains invalid characters.\n\nValid Characters: '0-9' -"); document.forms[form].elements[element].focus(); return false; } else { if (! (zip.length == 9 || zip.length == 5 || zip.length == 0)) { alert("The zip code should either be 5 or 9 characters long"); document.forms[form].elements[element].focus(); return false; } } } //------------------------------------------------------------------------------- function chkPhone(form,element) { var phoneNum = document.forms[form].elements[element].value; phoneNum = phoneNum.replace(/[\(\)\.\-\ ]/g, ''); if (isNaN(phoneNum)) { alert("The phone number contains invalid characters.\n\nValid Characters: - ( ) '0-9'"); document.forms[form].elements[element].focus(); return false; } else { if (phoneNum.length != 10 && phoneNum.length != 0) { alert("The phone number should be 10 digits in length."); document.forms[form].elements[element].focus(); return false; } } } //------------------------------------------------------------------------------- function chkEmail(form,element) { var emailAddress = document.forms[form].elements[element].value; if ((emailAddress.indexOf('@') <= 0 || emailAddress.indexOf('@',emailAddress.indexOf('@')+1)-emailAddress.indexOf('@') > 0) || ((emailAddress.charAt(emailAddress.length-4) != '.') && (emailAddress.charAt(emailAddress.length-3) != '.'))) { alert("Please enter one valid email address.\n\nExample: user@rainhail.com"); document.forms[form].elements[element].focus(); return false; } } //------------------------------------------------------------------------------- function chkDate (separator,form,element) { var date = document.forms[form].elements[element].value; date = date.replace(/[\/\.\-\ ]/g, separator); if (date.indexOf("-") < 1) { alert("The format of the date field is incorrect.\n\nValid Format: DD-MON-YYYY"); document.forms[form].elements[element].focus(); return false; } else { if (date.length < 10 || date.length > 11) { alert("The format of the date field is incorrect.\n\nValid Format: DD-MON-YYYY"); document.forms[form].elements[element].focus(); return false; } else { var dayIndex = date.indexOf(separator); var monthIndex = date.lastIndexOf(separator,date.length); var day = date.substring(0,dayIndex); var month = date.substring((dayIndex + 1),monthIndex); var year = date.substring((monthIndex + 1),date.length); if (day < 1 || day > 31) { alert("The day of the month must be between 1 and 31.\n\nValid Format: DD-MON-YYYY"); document.forms[form].elements[element].focus(); return false; } else { if (year < 1900 || year > 3000) { alert("The year value is out of bounds.\n\nValid Format: DD-MON-YYYY"); document.forms[form].elements[element].focus(); return false; } else { switch (month) { case "Jan": case "jan": case "JAN": month = "JAN"; break; case "Feb": case "feb": case "FEB": month = "FEB"; break; case "Mar": case "mar": case "MAR": month = "MAR"; break; case "Apr": case "apr": case "APR": month = "APR"; break; case "May": case "may": case "MAY": month = "MAY"; break; case "Jun": case "jun": case "JUN": month = "JUN"; break; case "Jul": case "jul": case "JUL": month = "JUL"; break; case "Aug": case "aug": case "AUG": month = "AUG"; break; case "Sep": case "sep": case "SEP": month = "SEP"; break; case "Oct": case "oct": case "OCT": month = "OCT"; break; case "Nov": case "nov": case "NOV": month = "NOV"; break; case "Dec": case "dec": case "DEC": month = "DEC"; break; default: alert("The month must be entered as an 3 character abbreviation.\n\nExample: DEC"); document.forms[form].elements[element].focus(); return false; } document.forms[form].elements[element].value = day + separator + month + separator + year; } } } } } //------------------------------------------------------------------------------- function chkSpace(title,form,element) { var field = document.forms[form].elements[element].value; var spc = " "; if (field.indexOf(spc) > -1) { alert(title + " must not contain spaces."); document.forms[form].elements[element].focus(); return false; } } //------------------------------------------------------------------------------- function cnfmField(msg,form,element1,element2) { var psswd = document.forms[form].elements[element1].value; var cnfrm = document.forms[form].elements[element2].value; if (psswd != cnfrm) { alert(msg); document.forms[form].elements[element1].value = ""; document.forms[form].elements[element2].value = ""; document.forms[form].elements[element1].focus(); return false; } }