/************************************************************** validate.js Set of JavaScript functions used for validation Original Source: JavaScript Validation 2.0, 19/Mar/2001 Jake Howlett, http://www.codestore.org/ Modifications/Additions: Medical Office Online, Inc. *********************************************************** The code contained herein contstitutes Medical Office Online, Inc's copyright and is intended for use by its customers and potential customers only. User may not modify, remove, delete, augment, add to, publish, transmit, participate in the transfer or sale of, create derivative works from, or in any way exploit any of the code contained herein, in whole or in part. This Web site is offered to the user conditioned on acceptance by the user without modification of the terms, conditions, and notices contained herein. By accessing and using this Web site, the User is deemed to have agreed to all such terms, conditions, and notices. ***********************************************************/ /*********************************************************** validateNumber() This function checks that the value of a field is a number and, optionally within a certain range. Arguments: val = Value to be checked min = Optional minimum allowed value max = Optional maximum allowed value ************************************************************/ function validateNumber(val, min, max){ if ( isNaN( val ) ) return false; if ( min && val < min ) return false; if ( max && val > max ) return false; return true; } /*********************************************************** dateComponents() This function splits a date in to the day, month and year components, depending on the format supplied. Used by Date Validation routine. Arguments: obj = Input whose value is to be checked format = date format, ie mm/dd or dd/mm ************************************************************/ function dateComponents(dateStr, format) { var results = new Array(); var datePat = /^(\d{1,2})(\/|-|\.)(\d{1,2})\2(\d{2}|\d{4})$/; var matchArray = dateStr.match(datePat); if (matchArray == null) { return null; } //check for two digit (20th century) years and prepend 19. matchArray[4] = (matchArray[4].length == 2) ? '19' + matchArray[4] : matchArray[4]; // parse date into variables if (format.charAt(0)=="d"){ //what format does the server use for dates? results[0] = matchArray[1]; results[1] = matchArray[3]; } else { results[1] = matchArray[1]; results[0] = matchArray[3]; } results[2] = matchArray[4]; return results; } /*********************************************************** valiDate() This function checks that the value of a date is in the correct format and, optionally, within a certain range. Arguments: obj = Input whose value is to be checked min = Optional minimum allowed value max = Optional maximum allowed value format = date format, ie mm/dd or dd/mm ************************************************************/ function valiDate(obj, min, max, format){ dateBits = dateComponents(obj.value, format); if (dateBits == null) return false; //Check it is a valid date first day = dateBits[0]; month = dateBits[1]; year = dateBits[2]; if ((month < 1 || month > 12) || (day < 1 || day > 31)) { // check month range return false; } //bk20070430 change ==31 to >30 // if ((month==4 || month==6 || month==9 || month==11) && day==31) { if ((month==4 || month==6 || month==9 || month==11) && day>30) { return false; } if (month == 2) { // check for february 29th var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0)); if (day>29 || (day==29 && !isleap)) { return false; } } //Now check whether a range is specified and if in bounds var theDate = new Date(dateBits[2], parseInt(dateBits[1]) - 1, dateBits[0]); if ( min ) { minBits = dateComponents (min, format); var minDate = new Date(minBits[2], parseInt(minBits[1]) - 1, minBits[0]); if ( minDate.getTime() > theDate.getTime() ) return false; } if ( max) { maxBits = dateComponents (max, format); var maxDate = new Date(maxBits[2], parseInt(maxBits[1]) - 1, maxBits[0]); if ( theDate.getTime() > maxDate.getTime() ) return false; } return true; } /*********************************************************** validateEmail() This function checks that the value of a field is a valid SMTP e-mail address ie x@xx.xx Arguments: obj = Input whose value is to be checked Original source: http://javascript.internet.com Author: Sandeep V. Tamhankar (stamhankar@hotmail.com) Note: Work in progress = validate SMTP OR Notes Canonical ************************************************************/ function validateEmail( obj ) { var emailStr = obj.value; var reg1 = /(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/; // not valid var reg2 = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/; // valid if ( !reg1.test( emailStr ) && reg2.test( emailStr ) ) { return true; } else { return false;} } /*********************************************************** validateTextdate() This function checks that the value of a text field is in a valid date format Arguments: obj = Input whose value is to be checked ************************************************************/ function validateTextDate( obj ) { //bk20070430 next line calls new function at end of this file and bypasses remainder of this function. return isValidDate(obj.value) var elems = obj.value.split("/"); result = (elems.length == 3); // should be three components if (result) { var month = parseInt(elems[0],10); var day = parseInt(elems[1],10); var year = parseInt(elems[2],10); result = !isNaN(month) && (month > 0) && (month < 13) && !isNaN(day) && (day > 0) && (day < 32) && !isNaN(year) && (elems[2].length == 4); } if (result) {return true;} else {return false;} } /*********************************************************** validateYear() This function checks that the value of a text field is in a valid 4 digit year format (ex. 1999). Arguments: strField = Input whose value is to be checked ************************************************************/ function validateYear(strField) { var re = /^[0-9]{4}$/; if (re.test(strField.value)){return true;} else {return false;} ; } /*********************************************************** validateInitial() This function checks that the value of a text field is in a valid US Phone Number format. Arguments: strField = Input whose value is to be checked ************************************************************/ function validateInitial(strField) { var re = /^[A-Z]{1}$/; if (re.test(strField.value)){return true;} else {return false;} ; } /*********************************************************** validateUSPhone() This function checks that the value of a text field is in a valid US Phone Number format. Arguments: pfield = Input whose value is to be checked ************************************************************/ function validateUSPhone(pfield) { var re = /^([0-9]{3}\-){2}[0-9]{4}$/; if (re.test(pfield.value)){return true;} else {return false;} ; } /*********************************************************** validateState() This function checks that the value of a text field is in a valid State format(ex. NY,IL,MA). Arguments: strField = Input whose value is to be checked ************************************************************/ function validateState(strField) { var re = /^[A-Z]{2}$/; if (re.test(strField.value)){return true;} else {return false;} ; } /*********************************************************** validateZip() This function checks that the value of a text field is in a valid ZIP format. Arguments: strField = Input whose value is to be checked ************************************************************/ function validateZip(strField) { var re = /^[0-9]{5}$/; if (re.test(strField.value)){return true;} else {return false;} ; } /*********************************************************** validateZip4() This function checks that the value of a text field is in a valid ZIP format. Arguments: strField = Input whose value is to be checked ************************************************************/ function validateZip4(strField) { var re = /^[0-9]{4}$/; if (re.test(strField.value)){return true;} else {return false;} ; } /*********************************************************** validateCurrency() This function checks that the value of a text field is a valid US Currency format. Arguments: pfield = Input whose value is to be checked ************************************************************/ function validateCurrency(obj) { var strValue = obj.value; if(strValue.indexOf('$') >= 0){ strValue = strValue.substring(1, strValue.length); //strips off the dollar sign } if (isNaN(strValue)) return false; //validates that the value is a number else return true; } /*********************************************************** validateSSN() This function checks that the value of a text field is in a valid US Social Security Number format. Arguments: pfield = Input whose value is to be checked ************************************************************/ function validateSSN(pfield) { var re = /^[0-9]{3}\-[0-9]{2}\-[0-9]{4}$/; if (re.test(pfield.value)){return true;} else {return false;} ; } /*********************************************************** validateNewUserName() This function checks that the value of a text field is in a valid User Name format. Must have at least 6 characters. Arguments: pfield = Input whose value is to be checked ************************************************************/ function validateNewUserName(pfield) { //bk20070601 disallow leading and trailing spaces // var re = /^[\w\s]{6,}$/; var re = /^\S[\w\s]{4,}\S$/; if (re.test(pfield.value)){return true;} else {return false;} ; } /*********************************************************** validateNewPassword() This function checks that the value of a text field is in a valid password format. Must have at least 6 characters. Arguments: pfield = Input whose value is to be checked ************************************************************/ function validateNewPassword(pfield) { //var re = /^[\w\s]{6,}$/; //this didn't allow symbols //bk20070601 disallow leading and trailing spaces // var re = /^.{6,}$/; var re = /^\S.{4,}\S$/; if (re.test(pfield.value)){return true;} else {return false;} ; } /*********************************************************** validateTime() This function checks that the value of a text field is in a valid Time format: ##:## AM/PM Arguments: pfield = Input whose value is to be checked ************************************************************/ function validateTime(pfield) { //bk20090218 require leading zero {1,2} --> {2} //var re = /^[0-9]{1,2}\:[0-9]{2}\s[AP]M$/; var re = /^[0-9]{2}\:[0-9]{2}\s[AP]M$/; //bk20090218 require leading zero validate ranges //if (re.test(pfield.value)){return true;} if (re.test(pfield.value) && (pfield.value.substr(0,2)<13) && (pfield.value.substr(0,2)>0) && (pfield.value.substr(3,2)<60)){return true;} else {return false;} ; } /*********************************************************** validateSentanceCase() This function checks that the value of a text field is in sentance case format Arguments: pfield = Input whose value is to be checked ************************************************************/ function validateSentenceCase(pfield) { var re = /^[A-Z0-9]{1}.*\S$/; var re1 = /^[A-Z,\s]+$/; if((re.test(pfield.value)) && (!re1.test(pfield.value)))return true; else return false; } /*********************************************************** validateTitle() bk20090126 correct comment. This function checks that the value of a text field is in title case format. Must begin with capital use letter, numbers or _'(),. and must not begin or end with space. Arguments: pfield = Input whose value is to be checked ************************************************************/ function validateTitle(pfield) { var re = /^[A-Z0-9]{1,6}[\w\-\'\(\)\,\.\s]*[\w\-\'\(\)\,\.]$/; if(re.test(pfield.value)) return true; else return false; } /*********************************************************** validateCleantext() This function checks that the value of a text field to make sure that there are no leading or trailing spaces. Arguments: pfield = Input whose value is to be checked ************************************************************/ function validateCleantext(pfield) { var re = /^\S.+\S$/; if(re.test(pfield.value)) return true; else return false; } /*********************************************************** validateSimpletext() This function checks that the value of a text field to make sure that there are no leading or trailing spaces and that the value only contains letters, numbers, hyphens, underscores and spaces (no other symbles allowed). Arguments: pfield = Input whose value is to be checked ************************************************************/ function validateSimpletext(pfield) { //consider (^[\w\-][\w\s\-]*\w$)|(^[A-Z]$) to allow single letter var re = /^[\w\-][\w\s\-]*\w$/; if(re.test(pfield.value)) return true; else return false; } /*********************************************************** locateFileUpload() Returns a handle to the file upload control on a form. Used to get around the fact that there is no consistent way to refer to the element cross-browser. ***********************************************************/ function locateFileUpload( f ) { for(var i = 0; i < f.elements.length; i ++) if( f.elements[i].type=='file' ){ return f.elements[i]; } } /*********************************************************** validateFileType() This function checks that the type of file being uploaded is allowed Arguments: obj = The File Upload control. fTyp = Allowed file types ************************************************************/ function validateFileType( obj, fTyp ) { dots = obj.value.split("."); fType = "." + dots[dots.length-1]; if ( fTyp != null && fTyp.indexOf(fType) == -1 ) return false; return true; } /*********************************************************** validateFileLimit() This function checks that the value in a file upload Arguments: obj = The File Upload control cur = Current number of file attachments max = Limit on allowed files ************************************************************/ function validateFileLimit( obj, cur, max ) { if ( cur >= max ) return false; return true; } /*********************************************************** isSomethingSelected() This function is passed an object of type redio group or check box. It then loops through all options and checks that one of them is selected, returning true if so. Arguments: obj = Reference to the parent object of the group. ************************************************************/ function isSomethingSelected( obj ){ for (var r=0; r < obj.length; r++){ if ( obj[r].checked ) return true; } } /*********************************************************** OnFailure() This function returns the failure message to the user and sets focus on the input in question. Arguments: obj = Input element on which to return focus lbl = Field Label to prepend on to the message msg = Array value for message to give the user ************************************************************/ function OnFailure( obj, lbl, msg, tab ){ var msgs = new Array(); msgs["text"] = tab + " is a required field. \n\nPlease enter a value."; msgs["textarea"] = tab + " is a required field. \n\nPlease enter a value."; msgs["select-one"] = tab + " is a required field. \n\nPlease select an entry."; msgs["select-multiple"] = tab + " is a required field. \n\nPlease select an entry."; msgs["checkbox"] = tab + " is a required field. \n\nPlease select an entry."; msgs["file"] = tab +" is a required upload. \n\nPlease select a file."; msgs["fileType"] = tab + " requires certain file types. \n\nPlease select a valid file type."; msgs["fileLimit"] = tab + " is a limited file upload. \n\nPlease reduce number of attachment(s) first."; msgs["radio"] = tab + " is a required field. \n\nPlease select an entry."; msgs["number"] = tab + " is a numeric field. \n\nPlease enter a valid number."; msgs["date"] = tab + " is a date field. \n\nPlease enter a valid date."; msgs["email"] = tab + " is an address field. \n\nPlease enter a valid e-mail address in the format name@domain.extension."; msgs["initial"] = tab + " is an initial field. \n\nPlease enter a single upper case letter with no period (ex. A)"; msgs["state"] = tab + " is a state field. \n\nPlease enter a valid state in the format NY"; msgs["zip"] = tab + " is a Zip Code field. \n\nPlease enter a valid zip code in the format 12345"; msgs["zip4"] = tab + " is a Zip Plus 4 field. \n\nPlease enter a valid zip plus 4 in the format 1234"; msgs["textdate"] = tab + " is a date field. \n\nPlease enter a date in the format MM/DD/YYYY."; msgs["usphone"]= tab + " is a phone number field. \n\nPlease enter a phone number in the format ###-###-####."; msgs["currency"]= tab + " is a Currency Field. \n\nPlease enter a dollar amount in the format 0.00"; msgs["ssn"]= tab + " is a social security number field. \n\nPlease enter a valid SSN in the format ###-##-####"; msgs["year"]= tab + " is a year field. \n\nPlease enter a valid 4 digit year(ex. 1999)"; msgs["username"]= tab + " is a username field. \n\nUser Names must have at least 6 Alpha-Numeric characters. The first and last letters cannot be spaces."; msgs["password"]= tab + " is a password field. \n\nPasswords must have at least 6 Alpha-Numeric characters. The first and last letters cannot be spaces."; msgs["sentence-case"]= tab + " is a sentence case field. \n\nPlease enter a value in sentence case\n(first letter must be capitalized, all caps not permitted, last letter cannot be a space)"; //bk20090126 correct message. // msgs["title"]= tab + " is a title field. \n\nPlease enter a value in sentence case\n(first letter must be capitalized, more than 4 capital letters not permitted, no weird symbols, last letter cannot be a space)"; msgs["title"]= tab + " is a title field. \n\nPlease enter a value in title case\n(first letter must be capitalized, use only letters and numbers, apostrophes, parentheses, underscores, dashes, commas, and periods. Cannot begin or end with spaces.)"; msgs["time"]= tab + " is a time field. \n\nPlease enter a valid time in the format 12:00 AM"; msgs["cleantext"]= tab + " is a validated field. \n\nPlease enter a valid value. The first and last letters cannot be spaces."; msgs["simpletext"]= tab + " is a validated field. \n\nPlease enter a valid value. You can only use letters, numbers, hyphens, underscores and spaces. The first and last letters cannot be spaces."; if(msg[1] || msg[2]){ //upper/lower bound ranges have been specified if(msg[1] && msg[2]){//range term = ( msg[0] == "date" )? " ("+msg[3]+")" : ""; alert(lbl + msgs[msg[0]] + term + " between " + msg[1] + " and " + msg[2]); } else if (msg[1]) {//lower bound term = ( msg[0] == "number" ) ? " greater than " : " (" + msg[3] + ") after "; alert(lbl + msgs[msg[0]] + term + msg[1]); } else {//upper bound term = ( msg[0] == "number" )? " less than " : " (" + msg[3] + ") before "; alert(lbl + msgs[msg[0]] + term + msg[2]); } } else {//no range given alert(lbl + msgs[msg[0]]); } // if (tab == "") obj.focus();//put currsor to errored field if user is on the errored tab return false; } /*********************************************************** validateFields() This function is passed an array of fields that are required to be filled in and iterates through each ensuring they have been correctly entered. ************************************************************/ function validateFields( f, a ){ for (var i=0; i < a.length; i++){ e = a[i][0]; var reqd = a[i][3]; var tabLoc if(a[i][4]) tabLoc = " " + a[i][4]; else tabLoc = ""; //checks input types: "text","select-one","select-multiple","textarea","checkbox","radio","file" if ((e.type == "text") || (e.type == "hidden") || (e.type == "password")){ if ((trim(e.value) == "") && (reqd == 1) ) return OnFailure(e, a[i][1], ["text"], tabLoc); if ( a[i][2] ) { switch ( a[i][2][0] ){ case "number": if (!validateNumber(e.value, a[i][2][1], a[i][2][2])) return OnFailure(e, a[i][1], ["number", a[i][2][1], a[i][2][2]], tabLoc); break case "usphone": if (((reqd == 0) && (trim(e.value) != "")) || (reqd == 1)) if (!validateUSPhone(e)) return OnFailure(e, a[i][1], ["usphone"], tabLoc); break case "currency": //bk20070430 remove trim since Notes will fail on open with blanks in currency field, so validate regardless // if (((reqd == 0) && (trim(e.value) != "")) || (reqd == 1)) if (((reqd == 0) && (e.value != "")) || (reqd == 1)) if (!validateCurrency(e)) return OnFailure(e, a[i][1], ["currency"], tabLoc); break case "date": //bk20070430 remove trim since Notes will fail on open with blanks in date field, so validate regardless // if (((reqd == 0) && (trim(e.value) != "")) || (reqd == 1)) if (((reqd == 0) && (e.value != "")) || (reqd == 1)) if (!valiDate(e, a[i][2][1], a[i][2][2], a[i][2][3])) return OnFailure(e, a[i][1], ["date", a[i][2][1], a[i][2][2], a[i][2][3]], tabLoc); break case "email": if (((reqd == 0) && (trim(e.value) != "")) || (reqd == 1)) if (!validateEmail(e)) return OnFailure(e, a[i][1], ["email"], tabLoc); break case "initial": if (((reqd == 0) && (trim(e.value) != "")) || (reqd == 1)) if (!validateInitial(e)) return OnFailure(e, a[i][1], ["initial"], tabLoc); break case "state": if (((reqd == 0) && (trim(e.value) != "")) || (reqd == 1)) if (!validateState(e)) return OnFailure(e, a[i][1], ["state"], tabLoc); break case "zip": if (((reqd == 0) && (trim(e.value) != "")) || (reqd == 1)) if (!validateZip(e)) return OnFailure(e, a[i][1], ["zip"], tabLoc); break case "zip4": if (((reqd == 0) && (trim(e.value) != "")) || (reqd == 1)) if (!validateZip4(e)) return OnFailure(e, a[i][1], ["zip4"], tabLoc); break case "textdate": //bk20070430 remove trim since Notes will fail on open with blanks in date field, so validate regardless // if (((reqd == 0) && (trim(e.value) != "")) || (reqd == 1)) if (((reqd == 0) && (e.value != "")) || (reqd == 1)) if ( !validateTextDate(e) ) return OnFailure(e, a[i][1], ["textdate"], tabLoc); break case "year": if (((reqd == 0) && (trim(e.value) != "")) || (reqd == 1)) if ( !validateYear(e) ) return OnFailure(e, a[i][1], ["year"], tabLoc); break case "ssn": if (((reqd == 0) && (trim(e.value) != "")) || (reqd == 1)) if (!validateSSN(e)) return OnFailure(e, a[i][1], ["ssn"], tabLoc); break case "username": if (((reqd == 0) && (trim(e.value) != "")) || (reqd == 1)) if (!validateNewUserName(e)) return OnFailure(e, a[i][1], ["username"], tabLoc); break case "password": if (((reqd == 0) && (trim(e.value) != "")) || (reqd == 1)) if (!validateNewPassword(e)) return OnFailure(e, a[i][1], ["password"], tabLoc); break case "sentence-case": if (((reqd == 0) && (trim(e.value) != "")) || (reqd == 1)) if (!validateSentenceCase(e)) return OnFailure(e, a[i][1], ["sentence-case"], tabLoc); break case "title": if (((reqd == 0) && (trim(e.value) != "")) || (reqd == 1)) if (!validateTitle(e)) return OnFailure(e, a[i][1], ["title"], tabLoc); break case "time": //bk20070430 remove trim since Notes will fail on open with blanks in time field, so validate regardless // if (((reqd == 0) && (trim(e.value) != "")) || (reqd == 1)) if (((reqd == 0) && (e.value != "")) || (reqd == 1)) if (!validateTime(e)) return OnFailure(e, a[i][1], ["time"], tabLoc); break case "cleantext": if (((reqd == 0) && (trim(e.value) != "")) || (reqd == 1)) if (!validateCleantext(e)) return OnFailure(e, a[i][1], ["cleantext"], tabLoc); break case "simpletext": if (((reqd == 0) && (trim(e.value) != "")) || (reqd == 1)) if (!validateSimpletext(e)) return OnFailure(e, a[i][1], ["simpletext"], tabLoc); break default: break }//switch }//level 1 if }//level 0 if else if (e.type == "file") { //make sure AT LEAST one file gets attached if ( a[i][2][1] == 0 && trim(e.value) == "" ) return OnFailure(e, a[i][1], ["file"]); if ( trim(e.value) != "") { //check type of file that is being uploaded if ( a[i][2][0] != null && validateFileType( e, a[i][2][0] ) == false ) return OnFailure(e, a[i][1], ["fileType"], tabLoc); //check that file limit has not been reached if ( a[i][2][2] != null && validateFileLimit( e, a[i][2][1], a[i][2][2] ) == false ) return OnFailure(e, a[i][1], ["fileLimit"], tabLoc); } } else if (e.type == "textarea"){ if (((reqd == 0) && (trim(e.value) != "")) || (reqd == 1)) if (trim(e.value) == "") return OnFailure(e, a[i][1], ["textarea"], tabLoc);} else if (e.type == "select-one"){ if (((reqd == 0) && (trim(e.value) != "")) || (reqd == 1)) if (e.selectedIndex == 0) return OnFailure(e, a[i][1], ["select-one"], tabLoc);} else if (e.type == "select-multiple"){ if (((reqd == 0) && (trim(e.value) != "")) || (reqd == 1)) if (e.selectedIndex == -1) return OnFailure(e, a[i][1], ["select-multiple"], tabLoc);} else { //must be a checkbox or a radio group if none of above if ( !e[0]) {//handle single item group first switch (e.type) { case "checkbox": if (((reqd == 0) && (trim(e.value) != "")) || (reqd == 1)) if ( !e.checked ) return OnFailure(e, a[i][1], ["checkbox"], tabLoc); break case "radio": if (((reqd == 0) && (trim(e.value) != "")) || (reqd == 1)) if ( !e.checked ) return OnFailure(e, a[i][1], ["radio"], tabLoc); break default: break } } else { //handle multi-item groups switch (e[0].type) { case "checkbox": if (((reqd == 0) && (trim(e.value) != "")) || (reqd == 1)) if ( !isSomethingSelected( e ) ) return OnFailure(e[0], a[i][1], ["checkbox"], tabLoc); break case "radio": if (((reqd == 0) && (trim(e.value) != "")) || (reqd == 1)) if ( !isSomethingSelected( e ) ) return OnFailure(e[0], a[i][1], ["radio"], tabLoc); break default: break } } } } //for loop return true; } /*********************************************************** setRequiredFieldStyles() This function is passed an array of fields that are to be validated. It selects from the array only the fields that are required and changes their style if the document is open for editing. ************************************************************/ function setRequiredFieldStyles(vArray, fieldClass, inEditMode, selectClass) { if(inEditMode == 1) for (var i=0; i < vArray.length; i++) if ((vArray[i][3] == 1) && (vArray[i][0].type != "hidden")) { //checks if field is required or just to be validated. and that it is not hidden if (vArray[i][2] == 'Radio Group') { //process all elements of a radio group var currObj = vArray[i][0] var namesArray = document.getElementsByName(currObj[0].name); for (var j=0; j < namesArray.length; j++) if (namesArray[j].type != "hidden") namesArray[j].className = fieldClass; } else if(vArray[i][0].tagName == "SELECT") vArray[i][0].className = selectClass; else vArray[i][0].className = fieldClass; } } /*********************************************************** clearRequiredFieldStyles() This function resets the style of the fields contained in the validate array to "". ************************************************************/ function clearRequiredFieldStyles(vArray, fieldClass, inEditMode, selectClass) { if(inEditMode == 1) for (var i=0; i < vArray.length; i++) if ((vArray[i][3] == 1) && (vArray[i][0].type != "hidden")) { //checks if field is required or just to be validated. and that it is not hidden if (vArray[i][2] == 'Radio Group') { //process all elements of a radio group var currObj = vArray[i][0] var namesArray = document.getElementsByName(currObj[0].name); for(var j=0; j < namesArray.length; j++) if((namesArray[j].type != "hidden")&&(namesArray[j].className == fieldClass)) namesArray[j].className = ""; } else vArray[i][0].className = ""; } } /************************* bk20070430 **************************/ /** * DHTML date validation script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/) */ // Declaring valid date character, minimum year and maximum year var dtCh= "/"; var minYear=1900; var maxYear=2100; function isInteger(s){ var i; for (i = 0; i < s.length; i++){ // Check that current character is number. var c = s.charAt(i); if (((c < "0") || (c > "9"))) return false; } // All characters are numbers. 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++){ var c = s.charAt(i); if (bag.indexOf(c) == -1) returnString += c; } return returnString; } function daysInFebruary (year){ // February has 29 days in any year evenly divisible by four, // EXCEPT for centurial years which are not also divisible by 400. return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 ); } function DaysArray(n) { for (var i = 1; i <= n; i++) { this[i] = 31 if (i==4 || i==6 || i==9 || i==11) {this[i] = 30} if (i==2) {this[i] = 29} } return this } function isValidDate(dtStr){ var daysInMonth = DaysArray(12) var pos1=dtStr.indexOf(dtCh) var pos2=dtStr.indexOf(dtCh,pos1+1) var strMonth=dtStr.substring(0,pos1) var strDay=dtStr.substring(pos1+1,pos2) var strYear=dtStr.substring(pos2+1) strYr=strYear if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1) if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1) for (var i = 1; i <= 3; i++) { if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1) } month=parseInt(strMonth) day=parseInt(strDay) year=parseInt(strYr) if (pos1==-1 || pos2==-1){ // alert("The date format should be : mm/dd/yyyy") return false } if (strMonth.length<1 || month<1 || month>12){ // alert("Please enter a valid month") return false } if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){ /// alert("Please enter a valid day") return false } if (strYear.length != 4 || year==0 || yearmaxYear){ // alert("Please enter a valid 4 digit year between "+minYear+" and "+maxYear) return false } if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){ // alert("Please enter a valid date") return false } return true }