var digits = "0123456789"; var lowercaseLetters = "abcdefghijklmnopqrstuvwxyz" var uppercaseLetters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" var whitespace = " \t\n\r"; var defaultEmptyOK = false var decimalPointDelimiter = "." var iEmail = "Please enter a valid email address (like your_name@company.com)" var iUSPhone = "Please enter a 10 digit U.S. phone number (like 310 555 1212 or 310 555 1212 x 1234)" var iZIPCode = "Please enter a 5-digit U.S. ZIP Code (like 92708)" var digitsInUSPhoneNumber = 10; var digitsInUSPhoneNumber2 = 12; var digitsInUSPhoneNumber3 = 13; var digitsInUSPhoneNumber4 = 14; var ZIPCodeDelimiters = "-"; var ZIPCodeDelimeter = "-" var validZIPCodeChars = digits + ZIPCodeDelimiters var digitsInZIPCode1 = 5 var digitsInZIPCode2 = 9 var decimalPointDelimiter = "." var phoneNumberDelimiters = "()-xX "; var validUSPhoneChars = digits + phoneNumberDelimiters; function CheckMinLeng(theField,lsize,s) { var ss = alltrim(theField.value); if (ss.length < lsize) return warnInvalid (theField, s); else return true; } function isEmpty(s) { return ((s == null) || (s.length == 0)) } function isWhitespace (s) { var i; if (isEmpty(s)) return true; for (i = 0; i < s.length; i++) { var c = s.charAt(i); if (whitespace.indexOf(c) == -1) return false; } return true; } function isDigit (c) { return ((c >= "0") && (c <= "9")) } function isInteger (s) { var i; if (isEmpty(s)) if (isInteger.arguments.length == 1) return defaultEmptyOK; else return (isInteger.arguments[1] == true); for (i = 0; i < s.length; i++) { var c = s.charAt(i); if (!isDigit(c)) return false; } return true; } function isFloat (s) { var i; var seenDecimalPoint = false; if (isEmpty(s)) if (isFloat.arguments.length == 1) return defaultEmptyOK; else return (isFloat.arguments[1] == true); if (s == decimalPointDelimiter) return false; for (i = 0; i < s.length; i++) { var c = s.charAt(i); if ((c == decimalPointDelimiter) && !seenDecimalPoint) seenDecimalPoint = true; else if (!isDigit(c)) return false; } return true; } function warnInvalid (theField, s) { theField.focus() theField.select() alert(s) return false } function warnMsg (theField, s) { theField.focus() alert(s) return false } function warnMsg (theField, s) { theField.focus() alert(s) return false } // ============================= function alltrim(inputString) { 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; } function checkEmptyString (theField, s) { if ((theField.value == null) || (theField.value.length == 0) || isWhitespace(theField.value)) // if (isWhitespace(theField.value)) // 10-31-04 return warnInvalid (theField, s); else return true; } function checkInteger (theField, s) { if (!isInteger(theField.value)) return warnInvalid (theField, s); else return true; } function checkFloat(theField, s) { if (!isFloat(theField.value)) return warnInvalid (theField, s); else return true; } function getListBoxIndex(lstbox) { var j=-1 for (var i = 0; i < lstbox.length; i++) { if (lstbox.options[i].selected == true ) { j=i; break } } return j } function getListBoxValue(lstbox) { var s="" for (var i = 0; i < lstbox.length; i++) { if (lstbox.options[i].selected == true ) { s= lstbox.options[i].value; break } } return s } function isListBoxSelected(lstbox) { var j=-1 for (var i = 0; i < lstbox.length; i++) { if (lstbox.options[i].selected == true ) { j=i return true } } return false } function checkListBoxSelected(lstbox,s) { if (isListBoxSelected(lstbox) == false) return warnMsg (lstbox, s); else return true; } function checkEmptyListBox(lstbox,s) { if (getListBoxValue(lstbox) == "") return warnMsg (lstbox, s); else return true; } function SelectListBoxItem(lstbox,s) { for (var i = 0; i < lstbox.length; i++) { if (alltrim(lstbox.options[i].value) == s ) { lstbox.options[i].selected = true ; break } } return i } function SelectListBoxItemByText(lstbox,s) { for (var i = 0; i < lstbox.length; i++) { if (alltrim(lstbox.options[i].text) == s ) { lstbox.options[i].selected = true ; break } } return i } function checkZero(theField, s) { if (theField.value == 0) return warnInvalid (theField, s); else return true; } function checkMaxiValue(theField, iValue, s) { if (theField.value > iValue ) return warnInvalid (theField, s); else return true; } function getRadioButtonValue (radio) { for (var i = 0; i < radio.length; i++) { if (radio[i].checked) { break } } return radio[i].value } function isRadioButtonSelected(RadioBtn) { var j=-1 for (var i = 0; i < RadioBtn.length; i++) { if (RadioBtn[i].checked == true ) { j=i return true } } return false } function checkAnyRadioButtonSelected(RadioBtn,s) { if (isRadioButtonSelected(RadioBtn) == false) { RadioBtn[0].focus(); alert(s); return false; } else return true; } function isEmail (s) { if (isEmpty(s)) if (isEmail.arguments.length == 1) return defaultEmptyOK; else return (isEmail.arguments[1] == true); // is s whitespace? if (isWhitespace(s)) return false; // there must be >= 1 character before @, so we // start looking at character position 1 // (i.e. second character) var i = 1; var sLength = s.length; // look for @ while ((i < sLength) && (s.charAt(i) != "@")) { i++ } if ((i >= sLength) || (s.charAt(i) != "@")) return false; else i += 2; // look for . while ((i < sLength) && (s.charAt(i) != ".")) { i++ } // there must be at least one character after the . if ((i >= sLength - 1) || (s.charAt(i) != ".")) return false; else return true; } function checkEmail (theField, emptyOK) { if (checkEmail.arguments.length == 1) emptyOK = defaultEmptyOK; if ((emptyOK == true) && (isEmpty(theField.value))) return true; else if (!isEmail(theField.value, false)) return warnInvalid (theField, iEmail); else return true; } function isZIPCode (s) { if (isEmpty(s)) if (isZIPCode.arguments.length == 1) return defaultEmptyOK; else return (isZIPCode.arguments[1] == true); return (isInteger(s) && ((s.length == digitsInZIPCode1) || (s.length == digitsInZIPCode2))) } function reformatZIPCode (ZIPString) { if (ZIPString.length == 5) return ZIPString; else return (reformat (ZIPString, "", 5, "-", 4)); } function checkZIPCode (theField, emptyOK) { if (checkZIPCode.arguments.length == 1) emptyOK = defaultEmptyOK; if ((emptyOK == true) && (isEmpty(theField.value))) return true; else { var normalizedZIP = stripCharsInBag(theField.value, ZIPCodeDelimiters) if (!isZIPCode(normalizedZIP, false)) return warnInvalid (theField, iZIPCode); else { // if you don't want to insert a hyphen, comment next line out theField.value = reformatZIPCode(normalizedZIP) return true; } } } function stripCharsInBag (s, bag) { var i; var returnString = ""; // Search through string's characters one by one. // If character is not in bag, append to returnString. for (i = 0; i < s.length; i++) { // Check that current character isn't whitespace. var c = s.charAt(i); if (bag.indexOf(c) == -1) returnString += c; } return returnString; } function reformat (s) { var arg; var sPos = 0; var resultString = ""; for (var i = 1; i < reformat.arguments.length; i++) { arg = reformat.arguments[i]; if (i % 2 == 1) resultString += arg; else { resultString += s.substring(sPos, sPos + arg); sPos += arg; } } return resultString; } function isUSPhoneNumber (s) { if (isEmpty(s)) if (isUSPhoneNumber.arguments.length == 1) return defaultEmptyOK; else return (isUSPhoneNumber.arguments[1] == true); return (isInteger(s) && ((s.length == digitsInUSPhoneNumber) || (s.length == digitsInUSPhoneNumber2) || (s.length == digitsInUSPhoneNumber3) || (s.length == digitsInUSPhoneNumber4) )) } function reformatUSPhone (USPhone) { return (reformat (USPhone, "(", 3, ") ", 3, "-", 4)) } function checkUSPhone (theField, emptyOK) { if (checkUSPhone.arguments.length == 1) emptyOK = defaultEmptyOK; if ((emptyOK == true) && (isEmpty(theField.value))) return true; else { var normalizedPhone = stripCharsInBag(theField.value, phoneNumberDelimiters) if (!isUSPhoneNumber(normalizedPhone, false)) return warnInvalid (theField, iUSPhone); else { // if you don't want to reformat as (123) 456-789, comment next line out // theField.value = reformatUSPhone(normalizedPhone) return true; } } } function SelectRadioItem(RadioBtn,s) { for (var i = 0; i < RadioBtn.length; i++) { if (RadioBtn[i].value == s ) { RadioBtn[i].checked = true ; break } } return i }