function checkEnter(evt) { evt = (evt) ? evt : event; var charCode = (evt.charCode) ? evt.charCode : ((evt.which) ? evt.which : evt.keyCode); if (charCode == 13 || charCode == 3) { return false; } else { return true; } } function focus_funct(id,bool) { var id_tr = id+'_tr'; if (bool == 'ON'){ document.getElementById(id_tr).style.backgroundColor = "silver"; }else{ document.getElementById(id_tr).style.backgroundColor = "transparent"; } } function trimAll(strValue) { var objRegExp = /^(\s*)$/; //check for all spaces if(objRegExp.test(strValue)) { strValue = strValue.replace(objRegExp, ''); if( strValue.length == 0) return strValue; } //check for leading & trailing spaces objRegExp = /^(\s*)([\W\w]*)(\b\s*$)/; if(objRegExp.test(strValue)) { //remove leading and trailing whitespace characters strValue = strValue.replace(objRegExp, '$2'); } return strValue; } var sError=''; //use for mat phone to ###-###-#### function phoneFormat(iString) { if(!iString == ('')) { var new_string = iString.replace(/[^0-9]/gi,''); if(new_string.substr(0,1) ==('1')) new_string = new_string.substr(1); var new_phone = new_string.substr(0,10); var final_phone = new_phone.substr(0,3)+"-"+new_phone.substr(3,3)+ "-"+new_phone.substr(6,4); return(final_phone); } else return(''); } function Validate(sValue,sId,sName,bRequired,sType,sMatch) { sValue = trimAll(sValue); var bError = false; if(bRequired==1) { if(!sValue.length > 0 ) { bError=true; var nonError4 = 'The field \"'+sName+'\" is required. Please enter a value.\n'; sError = sError.replace(nonError4,''); sError+='The field \"'+sName+'\" is required. Please enter a value.\n'; document.getElementById(sId).style.backgroundColor="red"; } else { document.getElementById(sId).style.backgroundColor="white"; if(sType=='string') { var objRegExp= /(^[a-zA-Z0-9\$\*\+\(\"\'_@#\s%\\]+[a-zA-Z0-9\.\$\*\+\-\(\)\"\'_!@#%\s\,&\=\?\:\;\/\\]+[a-zA-Z0-9\.\$\*\+\(\)\"\'_!@#\s%\,\?\\]$)|(^[a-zA-Z0-9\$\*\+\(\"\'_@#%]+[a-zA-Z0-9\.\$\*\+\(\)\"\'_!@#%\s\,]$)|(^[a-zA-Z0-9\.]$)/; var sFormat= "Any plain text. Not allowed:<>{}|/^~`"; } else if(sType=='state') { var objRegExp= /((^[a-zA-Z\-\.']+[a-zA-Z\-\.']+[a-zA-Z\-\.']$)|(^[a-zA-Z\-\.']+[a-zA-Z\-\.']$))/; var sFormat= "FL or fl or Florida"; } else if(sType=='integer') { var objRegExp= /\b\d+\b/; var sFormat= "1234567890"; } else if(sType=='phone') { sValue = phoneFormat(sValue); var objRegExp= /^(\d{3}-\d{3}-\d{4})*$/; var sFormat= "123-456-7890"; } else if(sType=='date') { var objRegExp= /^\d{1,2}(\-|\/|\.)\d{1,2}\1\d{4}$/; var sFormat= "mm/dd/yyyy or mm-dd-yyyy or mm.dd.yyyy"; } else if(sType=='float') { var dollarexp =/\$/; sValue = sValue.replace(dollarexp,''); var objRegExp= /[-+]?\b[0-9]+(\.[0-9]+)?\b/; var sFormat= "1,234,567,890.00"; } else if(sType=='zip') { var objRegExp= /(^\d{5}$|^\d{5}-\d{4}$)/; var sFormat= "12345-6789 or 12345"; } else if(sType=='email') { var objRegExp= /^(([A-Za-z0-9]+_+)|([A-Za-z0-9]+\-+)|([A-Za-z0-9]+\.+)|([A-Za-z0-9]+\++))*[A-Za-z0-9]+@((\w+\-+)|(\w+\.))*\w{1,63}\.[a-zA-Z]{2,6}$/i; var sFormat= "name@domain.com"; } if(!objRegExp.test(sValue)) { bError=true; var nonError1 = 'The field \"'+sName+'\" is invalid and required. Please enter a new value.\n The value must be formated like:\"'+sFormat+'\"\n'; var nonError2 = 'The field \"'+sName+'\" is invalid. Please enter a new value.\n The value must be formated like:\"'+sFormat+'\"\n'; sError = sError.replace(nonError1,''); sError = sError.replace(nonError2,''); sError+='The field \"'+sName+'\" is invalid and required. Please enter a new value.\n The value must be formated like:\"'+sFormat+'\"\n'; alert(sError); } if(!sMatch=='') { if(!sValue==document.getElementById(sMatch).value) { bError=true; var nonError3 = 'Please confirm that the field \"'+sName+'\" and its confirmation field \"'+sName+' Confirm\" match.\n'; sError = sError.replace(nonError3,''); sError+='Please confirm that the field \"'+sName+'\" and its confirmation field \"'+sName+' Confirm\" match.\n'; } } } } else { document.getElementById(sId).style.backgroundColor="white"; if(sValue.length > 0 ) { if(sType=='string') { var objRegExp= /(^[a-zA-Z0-9\$\*\+\(\"\'_@#\s%\\]+[a-zA-Z0-9\.\$\*\+\-\(\)\"\'_!@#%\s\,&\=\?\:\;\/\\]+[a-zA-Z0-9\.\$\*\+\(\)\"\'_!@#\s%\,\?\\]$)|(^[a-zA-Z0-9\$\*\+\(\"\'_@#%]+[a-zA-Z0-9\.\$\*\+\(\)\"\'_!@#%\s\,]$)|(^[a-zA-Z0-9\.]$)/; var sFormat= "Any plain text. Not allowed:<>{}|/^~`"; } else if(sType=='state') { var objRegExp= /((^[a-zA-Z\-\.']+[a-zA-Z\-\.']+[a-zA-Z\-\.']$)|(^[a-zA-Z\-\.']+[a-zA-Z\-\.']$))/; var sFormat= "FL or fl or Florida"; } else if(sType=='integer') { var objRegExp= /\b\d+\b/; var sFormat= "1234567890"; } else if(sType=='phone') { sValue = phoneFormat(sValue); var objRegExp= /^(\d{3}-\d{3}-\d{4})*$/; var sFormat= "123-456-7890"; } else if(sType=='date') { var objRegExp= /^\d{1,2}(\-|\/|\.)\d{1,2}\1\d{4}$/; var sFormat= "mm/dd/yyyy or mm-dd-yyyy or mm.dd.yyyy"; } else if(sType=='float') { var dollarexp =/\$/; sValue = sValue.replace(dollarexp,''); var objRegExp= /[-+]?\b[0-9]+(\.[0-9]+)?\b/; var sFormat= "1,234,567,890.00"; } else if(sType=='zip') { var objRegExp= /(^\d{5}$|^\d{5}-\d{4}$)/; var sFormat= "12345-6789 or 12345"; } else if(sType=='email') { var objRegExp= /^(([A-Za-z0-9]+_+)|([A-Za-z0-9]+\-+)|([A-Za-z0-9]+\.+)|([A-Za-z0-9]+\++))*[A-Za-z0-9]+@((\w+\-+)|(\w+\.))*\w{1,63}\.[a-zA-Z]{2,6}$/i; var sFormat= "name@domain.com"; } if(!objRegExp.test(sValue)) { bError=true; var nonError1 = 'The field \"'+sName+'\" is invalid and required. Please enter a new value.\n The value must be formated like:\"'+sFormat+'\"\n'; var nonError2 = 'The field \"'+sName+'\" is invalid. Please enter a new value.\n The value must be formated like:\"'+sFormat+'\"\n'; sError = sError.replace(nonError1,''); sError = sError.replace(nonError2,''); sError+='The field \"'+sName+'\" is invalid. Please enter a new value.\n The value must be formated like:\"'+sFormat+'\"\n'; alert(sError); } } } document.getElementById(sId).value = sValue; if(bError==true) { //alert(sError); document.getElementById(sId).style.backgroundColor="red"; //document.getElementById(sId).focus(); return false; } else { var nonError1 = 'The field \"'+sName+'\" is invalid and required. Please enter a new value.\n The value must be formated like:\"'+sFormat+'\"\n'; var nonError2 = 'The field \"'+sName+'\" is invalid. Please enter a new value.\n The value must be formated like:\"'+sFormat+'\"\n'; var nonError3 = 'Please confirm that the field \"'+sName+'\" and its confirmation field \"'+sName+' Confirm\" match.\n'; var nonError4 = 'The field \"'+sName+'\" is required. Please enter a value.\n'; sError = sError.replace(nonError4,''); sError = sError.replace(nonError3,''); sError = sError.replace(nonError1,''); sError = sError.replace(nonError2,''); return true; } }