function checkDecimals(fieldName, fieldValue, decimals) { if (fieldValue == "" || fieldValue == null) return true; if (isNaN(fieldValue)) { alert("That does not appear to be a valid number. Please try again."); fieldName.select(); fieldName.focus(); return false; } else { var regExp = '^[0-9]*(\.[0-9]{0,' + decimals + '})?$' var matchArray = fieldValue.match(regExp); if (matchArray == null) { alert ("Please enter a number with up to " + decimals + " decimal places. Please try again."); fieldName.select(); fieldName.focus(); return false; } } return true; }