var numericOnly = "0123456789"; var floatOnly = "0123456789."; var alphaOnly = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; var noSpecialOnly = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; var dateDelimiterOnly = '/'; var errorColor = '#E77A18'; var defaultColor = ''; function validateMLSSearchEntries() { var allValid = true; if(!validateEntryExists('mls_id')) { allValid = false; } return allValid; } function validateSalesSearchEntries() { var allValid = true; if(!validateEntryExists('state')) { allValid = false; } if(!validateEntryExists('type')) { allValid = false; } if(!validateEntryExists('status')) { allValid = false; } return allValid; } function validateRentalsSearchEntries() { var allValid = true; if(!validateEntryExists('state')) { allValid = false; } if(!validateEntryExists('move_in_date')) { allValid = false; } return allValid; } function validateEntryExists(fieldName) { var allValid = true; var field = document.getElementById(fieldName); var input = field.value; var errormsg = 'Field \'' + field.name + '\' must contain a value.'; if(input.length == 0) { allValid = false; } if(!allValid) { field.style.backgroundColor = errorColor; alert(errormsg); field.focus(); return false; } field.style.backgroundColor = defaultColor; return true; } function resetFieldColor(field) { field.style.backgroundColor = defaultColor; } function validateFloatOnly(field) { var errormsg = 'Please enter only numeric characters in the \'' + field.name + '\' field.'; var allValid = true; var input = field.value; var ch; for(i = 0; i < input.length && allValid == true; i++) { ch = input.charAt(i); if (floatOnly.indexOf(ch) == -1) { allValid = false; } } if(!allValid) { field.style.backgroundColor = errorColor; alert(errormsg); field.focus(); return false; } field.style.backgroundColor = defaultColor; return true; } function validateNumericOnly(field) { var errormsg = 'Please enter only numeric characters in the \'' + field.name + '\' field. (i.e. no special characters, including \'.,*?$#@*&\', etc...)'; var allValid = true; var input = field.value; var ch; for(i = 0; i < input.length && allValid == true; i++) { ch = input.charAt(i); if (numericOnly.indexOf(ch) == -1) { allValid = false; } } if(!allValid) { field.style.backgroundColor = errorColor; alert(errormsg); field.focus(); return false; } field.style.backgroundColor = defaultColor; return true; } function validateAlphaOnly(field) { var errormsg = 'Please enter only alphabetic characters in the \'' + field.name + '\' field.'; var allValid = true; var input = field.value; var ch; for(i = 0; i < input.length && allValid == true; i++) { ch = input.charAt(i); if (alphaOnly.indexOf(ch) == -1) { allValid = false; } } if(!allValid) { field.style.backgroundColor = errorColor; alert(errormsg); field.focus(); return false; } field.style.backgroundColor = defaultColor; return true; } function validateFullDate(field) { var errormsg = 'Please enter a valid date in the \'' + field.name + '\' field. (i.e. 10/20/2007, 02/15/1999, etc...)'; var allValid = true; var fullDate = field.value; count = 0; if(fullDate.length == 0) { field.style.backgroundColor = defaultColor; return true; } for(i = 0; i < fullDate.length; i++) { ch = fullDate.charAt(i); if(dateDelimiterOnly.charAt(0) == ch) { count++; } } if(count != 2) { field.style.backgroundColor = errorColor; alert(errormsg); field.focus(); allValid = false; return false; } var date = new Date(); var temp = new Array(); temp = fullDate.split(dateDelimiterOnly.charAt(0)); if(temp[0].length != 2 || temp[0] == 00) { field.style.backgroundColor = errorColor; alert(errormsg); field.focus(); allValid = false; return false; } else { if(temp[0] == 12) { temp[0] = 0; } date.setMonth(temp[0]); } if(temp[1].length != 2) { field.style.backgroundColor = errorColor; alert(errormsg); field.focus(); allValid = false; return false; } else { date.setDate(temp[1]); } if(temp[2].length != 4) { field.style.backgroundColor = errorColor; alert(errormsg); field.focus(); allValid = false; return false; } else { date.setFullYear(temp[2]); } if(temp[0] != date.getMonth() || temp[1] != date.getDate() || temp[2] != date.getFullYear()) { field.style.backgroundColor = errorColor; alert(errormsg); field.focus(); allValid = false; return false; } field.style.backgroundColor = defaultColor; return true; } function validate4DigitYear(field) { var errormsg = 'Please enter a valid 4-digit year in the \'' + field.name + '\' field. (i.e. 1980, 2000, etc...)'; var allValid = true; var year = field.value; if(year.length == 0) { field.style.backgroundColor = defaultColor; return true; } if(year.length != 4) { field.style.backgroundColor = errorColor; alert(errormsg); field.focus(); allValid = false; return false; } var date = new Date(); date.setFullYear(year); if(year != date.getFullYear()) { field.style.backgroundColor = errorColor; alert(errormsg); field.focus(); allValid = false; return false; } field.style.backgroundColor = defaultColor; return true; } function validateMonthYearDate(field) { var errormsg = 'Please enter a valid date in the \'' + field.name + '\' field. (i.e. 07/2009, 01/2010, etc...)'; var allValid = true; var fullDate = field.value; count = 0; if(fullDate.length == 0) { field.style.backgroundColor = defaultColor; return true; } for(i = 0; i < fullDate.length; i++) { ch = fullDate.charAt(i); if(dateDelimiterOnly.charAt(0) == ch) { count++; } } if(count != 1) { field.style.backgroundColor = errorColor; alert(errormsg); field.focus(); allValid = false; return false; } var date = new Date(); var temp = new Array(); temp = fullDate.split(dateDelimiterOnly.charAt(0)); if(temp[0].length != 2 || temp[0] == 00) { field.style.backgroundColor = errorColor; alert(errormsg); field.focus(); allValid = false; return false; } else { if(temp[0] == 12) { temp[0] = 0; } date.setMonth(temp[0]); } if(temp[1].length != 4) { field.style.backgroundColor = errorColor; alert(errormsg); field.focus(); allValid = false; return false; } else { date.setFullYear(temp[1]); } if(temp[0] != date.getMonth() || temp[1] != date.getFullYear()) { field.style.backgroundColor = errorColor; alert(errormsg); field.focus(); allValid = false; return false; } field.style.backgroundColor = defaultColor; return true; }