function trim(inputString) { // Removes leading and trailing spaces from the passed string. Also removes // consecutive spaces and replaces it with one space. If something besides // a string is passed in (null, custom object, etc.) then return the input. if (typeof inputString != "string") { return inputString; } var retValue = inputString; var ch = retValue.substring(0, 1); while (ch == " ") { // Check for spaces at the beginning of the string retValue = retValue.substring(1, retValue.length); ch = retValue.substring(0, 1); } ch = retValue.substring(retValue.length-1, retValue.length); while (ch == " ") { // Check for spaces at the end of the string retValue = retValue.substring(0, retValue.length-1); ch = retValue.substring(retValue.length-1, retValue.length); } while (retValue.indexOf(" ") != -1) { // Note that there are two spaces in the string - look for multiple spaces within the string retValue = retValue.substring(0, retValue.indexOf(" ")) + retValue.substring(retValue.indexOf(" ")+1, retValue.length); // Again, there are two spaces in each of the strings } return retValue; // Return the trimmed string back to the user } /********************************************************* validateText() This function checks to make sure the user has entered data into a text-only field. Arguments: fld = field errMsg = english name of field for display on error **********************************************************/ function validateText(fld, errMsg) { if(trim(fld.value)=="") { alert("Please enter a value for " + errMsg + "."); fld.focus(); fld.style.backgroundColor='#E61117' ; fld.style.color='#ffffff'; return false; }//endif fld.style.backgroundColor='#DCDCDC' ; fld.style.color='#000000'; return true; }//endfunction validatetext /********************************************************* validateNumber() This function checks that the value of a field is a number and, optionally within a certain range. Arguments: fld = field errMsg = english name of field for display on error min = Optional minimum allowed value max = Optional maximum allowed value **********************************************************/ function validateNumber(fld, errMsg, min, max) { if(fld.value=="") { alert("Please enter a value for " + errMsg + "."); fld.focus(); fld.style.backgroundColor='#E61117' ; fld.style.color='#ffffff'; return false; }//endif //check to see if it is a number var n=parseFloat(fld.value); if(isNaN(n)) { alert("Please enter a valid number for " + errMsg + "."); fld.focus(); fld.style.backgroundColor='#E61117' ; fld.style.color='#ffffff'; return false; }//endif // check to see if the number is less than the minimum if ( min && n < min ) { alert("Please enter a number greater than " + min + " for " + errMsg + "."); fld.focus(); fld.style.backgroundColor='#E61117' ; fld.style.color='#ffffff'; return false; }//endif // check to see if the number is more than the maximum if ( max && n > max ) { alert("Please enter a number less than " + max + " for " + errMsg + "."); fld.focus(); fld.style.backgroundColor='#E61117' ; fld.style.color='#ffffff'; return false; }//endif fld.style.backgroundColor='#DCDCDC' ; fld.style.color='#000000'; return true; }//endfunction validateNumber /********************************************************* validateDate() This function checks to make sure the user has entered a date. Arguments: fld = field errMsg = english name of field for display on error **********************************************************/ function validateDate(fld, errMsg) { var stDate = new Date(fld.value); if (stDate == "NaN") { alert("Please enter a valid date for " + errMsg + "."); fld.focus(); fld.style.backgroundColor='#E61117' ; fld.style.color='#ffffff'; return false; } fld.style.backgroundColor='#DCDCDC' ; fld.style.color='#000000'; return true; }//endfunction validateDate /********************************************************* validateSelect() This function checks to make sure the user has selected an option from a combobox or multi-select list box. Arguments: fld = field errMsg = english name of field for display on error **********************************************************/ function validateSelect(fld, errMsg) { var idx=fld.selectedIndex; if(idx== -1) { alert("Please choose a value for " + errMsg + "."); fld.focus(); return false; }//endif return true; }//endfunction validateSelect /********************************************************* validateCombobox() This function checks to make sure the user has selected an option from a combobox. (The first option should always be "(please select)" Arguments: fld = field errMsg = english name of field for display on error **********************************************************/ function validateCombobox(fld, errMsg) { var idx=fld.selectedIndex; if(idx== -1 || idx==0 ) { alert("Please choose a value for " + errMsg + "."); fld.focus(); return false; }//endif return true; }//endfunction validateCombobox /********************************************************* validateRadio() This function checks to make sure the user has entered an option for a radio button Arguments: fld = field errMsg = english name of field for display on error **********************************************************/ function validateRadio(fld, errMsg) { for(i=0;i -1) { phone = phone.replace(".", "-"); } fld.value = phone; return true; } // end if // Phone entered with no punctuation if (phone.length == 10) { phone = phone.substr(0, 3) + "-" + phone.substr(3, 3) + "-" + phone.substr(6, 4); fld.value = phone; return true; } // end if // we can't deal with this format alert("Please enter your phone number in one of the following formats:" + "\n\n 999.999.9999 or " + "\n 999-999-9999 or " + "\n 9999999999."); fld.focus(); return false; } // end function validatePhone /********************************************************* checkAmount() This function checks to make sure the user has entered a valid currency value. Arguments: fld = field **********************************************************/ function checkAmount (fld) { var input = fld.value; num = input.toString().replace(/,|\$/, '') var n = parseFloat(num); if (fld.value !="") { if(isNaN(n)) { alert ("Amount must be a numeric value."); fld.focus(); return input; } // end if return formatCurrency(n); } return input; } /********************************************************* formatCurrency() This is a helper function for checkAmount() **********************************************************/ function formatCurrency(input) { num = input.toString().replace(/,|\$/, '') if(isNaN(num)) num = "0"; sign = (num == (num = Math.abs(num))); num = Math.floor(num*100+0.50000000001); cents = num%100; num = Math.floor(num/100).toString(); if(cents<10) cents = "0" + cents; for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++) num = num.substring(0,num.length-(4*i+3))+','+ num.substring(num.length-(4*i+3)); return (((sign)?'':'-') + num + '.' + cents); }