var whitespace = " \t\n\r"; var defaultEmptyOK = false // m is an abbreviation for "missing" var mPrefix = "" var mSuffix = " is a required field. Please enter it now." function checkBarcode(field){ var s = "The barcode you entered is invalid. It should match the pattern 22101 123456789. Please try again."; bcode = field.value; if (isWhitespace(bcode)) return warnEmpty (field, "Barcode"); bcode = stripWhitespace(bcode); bcode = bcode.substr(5); if (bcode.length != 9) return warnInvalid(field, s); for (i = 0; i < 9; i++){ var c = bcode.charAt(i); if (!isDigit(c)) return warnInvalid(field, s); } document.regForm.barcode.value = bcode; return true; } function checkRoom(list){ if ( list.selectedIndex == 0) { list.focus(); alert ("Please select a room from the list"); return false; } else {return true;} } function checkSubmitter(form){ if (form.elements["Submitter"].selectedIndex == 0){ return ( checkString(form.elements["lName"],"Last Name") && checkString(form.elements["fName"],"First Name") && checkString(form.elements["Phone"],"Campus Phone") && checkString(form.elements["Email"],"E-mail Address") ) } else return true; } function checkDate(field){ str = field.value; re1 = /^\d{1,2}\/\d{1,2}(\/\d{2})$/; re2 = /^\d{1,2}\/\d{1,2}$/ if (re1.test(str) || re2.test(str)) return true; else return warnInvalid(field, "Enter the date in the form 3/5/01") } function checkTime(field){ str = field.value; re1 = /^\d{1,2}\s[ap]m$/; re2 = /^\d{1,2}:\d{2}\s[ap]m$/; if (re1.test(str) || re2.test(str)) return true; else return warnInvalid(field, "Enter the time in the form 10 am or 3:30 pm") } function checkZero(theField, m){ s = theField[theField.selectedIndex].value; t = theField[theField.selectedIndex].text; if ((s == null) || (s.length == 0) || (s == 0)){ theField.focus(); alert("Please select " + m); return false; } else return true; } function isDigit (c) { return ((c >= "0") && (c <= "9")) } function isEmpty(s){ return ((s == null) || (s.length == 0)) } function isWhitespace (s){ var i; // Is s empty? if (isEmpty(s)) return true; // Search through string's characters one by one // until we find a non-whitespace character. // When we do, return false; if we don't, return true. for (i = 0; i < s.length; i++) { // Check that current character isn't whitespace. var c = s.charAt(i); if (whitespace.indexOf(c) == -1) return false; } // All characters are whitespace. return true; } function stripWhitespace (s){ return stripCharsInBag (s, whitespace) } // Removes all characters which appear in string bag from string s. 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 warnEmpty (theField, s) { theField.focus() alert(mPrefix + s + mSuffix) return false } function warnInvalid (theField, s){ theField.focus() theField.select() alert(s) return false } // checkString (TEXTFIELD theField, STRING s, [, BOOLEAN emptyOK==false]) // // Check that string theField.value is not all whitespace. // // For explanation of optional argument emptyOK, // see comments of function isInteger. function checkString (theField, s, emptyOK) { // Next line is needed on NN3 to avoid "undefined is not a number" error // in equality comparison below. if (checkString.arguments.length == 2) emptyOK = defaultEmptyOK; if ((emptyOK == true) && (isEmpty(theField.value))) return true; if (isWhitespace(theField.value)) return warnEmpty (theField, s); else return true; }