// Purpose: Global Variables // Designed: 1999/03/08 - KHS href = location.href.toLowerCase(); //compare against lowercase href for ".nsf" pos=href.lastIndexOf ('.nsf', href.length-1); dbPath=href.substring (0, pos+4); var gEditFieldValue = ""; var gCheckBox = ""; var gEditField; var gsSpace = " "; var gsInvalidNetworkCharacters = " ~!@#$%^&*()-=+_{}[]|\;:'<>,./?"; /* ====================== Purpose: To validate to input date greater than current date . Designed: Linden Devine Oct 20, 2009 ====================== */ function FailDateLessToday( sField1, vType ) { isAvailable1 = FieldAvailable(sField1); var today = new Date(); if (isAvailable1 == true){ vField1 = eval("document.forms[0]."+ sField1); // get the field values. theValue1 = getFieldValue (vField1, vType); // return the current date in mm/dd/yyyy format as string theValue2 = today.getMonth()+1+"/"+today.getDate()+"/"+(today.getYear()); var monDate1 = parseInt( theValue1.substring(0,2),10); var dayDate1 = parseInt( theValue1.substring(3,5),10); var yearDate1 = parseInt( theValue1.substring(6,10),10); var dtInput1 = new Date(yearDate1, monDate1, dayDate1); var monDate2 = parseInt( theValue2.substring(0,2),10); var dayDate2 = parseInt( theValue2.substring(3,5),10); var yearDate2 = parseInt( theValue2.substring(6,10),10); var dtInput2 = new Date(yearDate2, monDate2, dayDate2); if (dtInput1 < dtInput2) { vField.focus(); return (true); } } return; } /* ====================== Purpose: To validate if input date 1 less than input date 2 . Designed: Linden Devine Sep 10, 2009 ====================== */ function FailDateGreater( sField1, sField2, vType ) { isAvailable1 = FieldAvailable(sField1); isAvailable2 = FieldAvailable(sField2); if (isAvailable1 == true){ if (isAvailable2 == true){ vField1 = eval("document.forms[0]."+ sField1); vField2 = eval("document.forms[0]."+ sField2); // get the field values. theValue1 = getFieldValue (vField1, vType); theValue2 = getFieldValue (vField2, vType); var monDate1 = parseInt( theValue1.substring(0,2),10); var dayDate1 = parseInt( theValue1.substring(3,5),10); var yearDate1 = parseInt( theValue1.substring(6,10),10); var dtInput1 = new Date(yearDate1, monDate1, dayDate1); var monDate2 = parseInt( theValue2.substring(0,2),10); var dayDate2 = parseInt( theValue2.substring(3,5),10); var yearDate2 = parseInt( theValue2.substring(6,10),10); var dtInput2 = new Date(yearDate2, monDate2, dayDate2); if (dtInput1 < dtInput2) { // vField.value=""; vField.focus(); return (true); } } return; } return; } function failEqual( sField1, sField2, vMessage, vType ) { isAvailable1 = FieldAvailable(sField1); isAvailable2 = FieldAvailable(sField2); if (isAvailable1 == true){ if (isAvailable2 == true){ vField1 = eval("document.forms[0]."+ sField1); vField2 = eval("document.forms[0]."+ sField2); if (vField1.value != vField2.value ) { vField1.value=""; vField2.value=""; alertBox (vField1, vMessage, vType ); vField1.focus(); return (true); } } return; } return; } /* ================================= Purpose: Trim leading spaces from field. ================================= */ function trimsp(s) { //alert("==" + s + "=="); while (s.substring(0,1) == ' ') { s = s.substring(1,s.length); } while (s.substring(s.length-1,s.length) == ' ') { s = s.substring(0,s.length-1); } return s; } // end of trimsp /* ================================= Purpose: Validates an field containing either null, all spaces or not available for validation. Designed: Kurt Saik, 1999/03/08 ================================= */ function failNull( sField, vMessage, vType) { // // Is the field available for validation if (FieldAvailable(sField) == true){ vField = eval("document.forms[0]."+ sField); // // get the field value... theValue = getFieldValue (vField, vType); // // if the field value is null, we fail and return true... if ( theValue == "" ) { // alertBox ( vField, vMessage, vType ); // return ( true ); return ( false ); } }// end of (FieldAvailable(sField) == true) } // end of failNull /* ====================== Purpose: To validate to field for the same data. Designed: Kurt Saik Jul 11, 2002 ====================== */ function failEqual( sField1, sField2, vMessage, vType ) { isAvailable1 = FieldAvailable(sField1); isAvailable2 = FieldAvailable(sField2); if (isAvailable1 == true){ if (isAvailable2 == true){ vField1 = eval("document.forms[0]."+ sField1); vField2 = eval("document.forms[0]."+ sField2); if (vField1.value != vField2.value ) { vField1.value=""; vField2.value=""; alertBox (vField1, vMessage, vType ); vField1.focus(); return (true); } } return; } return; } /* ====================== Purpose: To validate multiple selections within a list field. Designed: Kurt Saik Jun 17, 2002 ====================== */ function failMultipleSelections( sField, vValue, vMessage, vType ) { isAvailable = FieldAvailable(sField); if (isAvailable == true){ vField = eval("document.forms[0]."+ sField); var iCount = 0; for (i=0;i < vField.length;i++){ switch(vType ) { case "checkbox": if (vField[i].checked==true){ iCount = iCount + 1 } break; case "list": if (vField[i].selected==true){ iCount = iCount + 1 } break; } //--end of switch } if (iCount > vValue ) { alertBox (vField, vMessage, vType ) return (true) } } return; } /* ====================== Purpose: To validate field length is not longer then allowed. Designed: Kurt Saik 29/03/1999 ====================== */ function failMaxLength( sField, vValue, vMessage, vType ) { isAvailable = FieldAvailable(sField); if (isAvailable == true){ vField = eval("document.forms[0]."+ sField); if (vField.value.length > vValue) { alertBox (vField, vMessage, vType ) return (true) } } return; } /* ====================== Purpose: To validate field length is equal to intended length Designed: Kurt Saik 29/03/1999 ====================== */ function failEqualLength( sField, vValue, vMessage, vType ) { isAvailable = FieldAvailable(sField); if (isAvailable == true){ vField = eval("document.forms[0]."+ sField); if (vField.value.length != vValue) { alertBox (vField, vMessage, vType ) return (true) } } return; } /* ====================== Purpose: To evaluate mask types Designed: Kurt Saik 29/03/1999 ====================== */ function failMask( sField, vMessage, vType ) { isAvailable = FieldAvailable(sField); if (isAvailable == true){ sStatus = ""; vField = eval("document.forms[0]."+ sField); switch(vType ) { case "phone": sStatus = PhoneValues(vField); if (sStatus!=false){ vField.focus(); vField.value = sStatus; } break; case "creditcard": // Function still pending development break; case "postal": sStatus = PostalValues(vField) if (sStatus!=false){ vField.focus(); vField.value = sStatus; } break; case "serial": sStatus = SerialValues(vField); break; case "networkID": sStatus = IDValues(vField); break; case "corpcard": sStatus = CreditCardNumbers(vField); break; case "costcentre": sStatus = CostCentreValues(vField); break; case "number": sStatus = NumberValues(vField); if (sStatus!=false){ vField.focus(); vField.value = sStatus; } break; case "numeric": sStatus = NumericValues(vField); if (sStatus==false){ vField.focus(); vField.select(); } break; case "alpha": sStatus = AlphaValues(vField); if (sStatus!=false){ vField.focus(); vField.value = sStatus; }else{ vField.focus(); vField.select(); } break; case "date": sStatus = DateValues(vField); if (sStatus!=false){ vField.focus(); vField.value = sStatus; }else{ vField.focus(); vField.select(); } break; case "email": sStatus = EmailValues(vField); if (sStatus!=false){ vField.focus(); vField.value = sStatus; }else{ vField.focus(); vField.select(); } break; case "url": sStatus = URLValues(vField); if (sStatus!=false){ vField.focus(); vField.value = sStatus; }else{ vField.focus(); vField.select(); } break; } //--end of switch if (sStatus == false){ alertBox (vField, vMessage, vType ); return ( true ); } } return; } //--end of function /* ====================== Purpose: To only allow alpha values. Designed: Kurt Saik 11/15/2000 ====================== */ function AlphaValues(vField){ var sOrigValue = vField.value; re = /[0-9]/ iPosition = sOrigValue.search(re); if (iPosition == -1){ return (sOrigValue) }else{ return false; } } //--end of function // /* ====================== Purpose: To allow only numerical values. Designed: Kurt Saik 11/15/2000 ====================== */ function NumericValues(vField){ var sOrigValue = vField.value; re = /[A-Za-z]/ iPosition = sOrigValue.search(re); if (iPosition == -1){ return true; }else{ return false; } } //--end of function // /* ====================== Purpose: To validate amount values Designed: Kurt Saik 05/04/1999 ====================== */ function NumberValues(vField){ var sOrigValue = vField.value; var sStriptValue = ""; var sNewValue = ""; re = /[0-9]/ iPosition = sOrigValue.search(re); if (iPosition != -1){ sStriptValue = sOrigValue.substring(0,iPosition); sNewValue = RemoveInvalid(sStriptValue,gsInvalidNetworkCharacters); }else{ sNewValue = RemoveInvalid(sOrigValue,gsInvalidNetworkCharacters); } //--end of If return (sNewValue); } //--end of function // /* ====================== Purpose: To remove invalid values Designed: Kurt Saik 07/08/1999 ====================== */ function RemoveInvalid(sValue,sInvalid){ var str = sValue; var sChar = ""; var newstr = ""; for (iInvalidCounter=0; iInvalidCounter < sInvalid.length ; iInvalidCounter++){ sChar = "\\" + sInvalid.charAt(iInvalidCounter); re = new RegExp(sChar); for (iCounter=0; iCounter < str.length; iCounter++){ if ( re.test(str)==false){ iCounter = str.length }else{ newstr=str.replace(re, ""); str=newstr; } //--end of If } //--end of for } //--end of for return (str); } //--end of function // /* ====================== Purpose: To validate phone numbers Designed: Kurt Saik 05/04/1999 ====================== */ function PhoneValues(vField){ var sNewValue = ""; sNewValue = RemoveInvalid(vField.value,gsInvalidNetworkCharacters); if (sNewValue.length <= 6){ return false; }else{ if (sNewValue.length >= 12){ return false; }else{ switch(sNewValue.length ) { case 7: return (sNewValue.substring(0,3) + "-" + sNewValue.substring(3,7)); break; case 8: return false; break; case 9: return false; break; case 10: return ("(" + sNewValue.substring(0,3) + ")" + sNewValue.substring(3,6) + "-" + sNewValue.substring(6,10)); break; case 11: return (sNewValue.substring(0,1)+ "(" + sNewValue.substring(1,4) + ")" + sNewValue.substring(4,7) + "-" + sNewValue.substring(7,11)); break; } //--end of switch } //--end of If } //--end of If } //--end of function // /* ====================== Purpose: To return string month values Designed: Kurt Saik, Jun 17, 2002 ====================== */ function MonthString(iMonth,iValue){ var sMonth = ""; switch(iMonth) { case 0: sMonth="January"; break; case "1": sMonth="February"; break; case 2: sMonth="March"; break; case 3: sMonth="April"; break; case 4: sMonth="May"; break; case 5: sMonth="June"; break; case 6: sMonth="July"; break; case 7: sMonth="August"; break; case 8: sMonth="September"; break; case 9: sMonth="October"; break; case 10: sMonth="November"; break; case 11: sMonth="December"; break; } //--end of switch sMonth = sMonth.substring (0, iValue); return (sMonth); } // /* ====================== Purpose: To validate date values Designed: Kurt Saik, Jun 17, 2002 ====================== */ function DateValues(vField){ var date = new Date(vField.value); var sDate =""; if (isNaN(date.getDate())){ return false; }else{ day = date.getDate() month = MonthString(date.getMonth(),3) year = date.getYear() return (month + " " + day + ", " + year); } } //--end of function /* ====================== Purpose: To validate URL values Designed: Kurt Saik, Jul 14, 2003 ====================== */ function URLValues(vField){ var sNewValue = ""; sNewValue = RemoveInvalid(vField.value," ~!@#$%^&*()-=+_{}[]|\;:'<>,/?"); // The following will work, www.aa.ca or intra..gov.on.ca // e.g. alpha or numeric for 2 characters, then a dot, then alpha or numeric for 2 characters, then a dot, then alpha or numeric for 2 characters re = /[A-Za-z0-9_]{2,}.?[A-Za-z0-9_]{2,}.?[A-Za-z0-9_]{2,}/; if ( re.test(sNewValue)){ return (sNewValue) }else{ return false; } } //--end of function /* ====================== Purpose: To validate cost centre numbers Designed: Kurt Saik 05/19/1999 ====================== */ function EmailValues(vField) { // @. OR .@ OR .blank OR . before @ OR no . OR no @ sField = eval(vField) var sRequired_1 = sField.value.indexOf ('@',0) var sRequired_2 = sField.value.indexOf ('.',0) //var sEmail = sField.value //var sDotPos = sEmail.lastIndexOf ('.', sEmail.length-1); //alert(sDotPos) var sFailed = false if (sRequired_1 == -1 || sRequired_2 == -1){ return false; } return (sField.value); } // /* ====================== Purpose: To validate postal code values Designed: Kurt Saik 05/04/1999 ====================== */ function PostalValues(vField){ var sNewValue = ""; sNewValue = RemoveInvalid(vField.value,gsInvalidNetworkCharacters); if (sNewValue.length == 6){ re = /[A-Za-z]{1}\d{1}[A-Za-z]{1}\d{1}[A-Za-z]{1}\d{1}/ if ( re.test(sNewValue)){ return (sNewValue) }else{ return false } }else{ return false } } //--end of function // /* ====================== Purpose: To validate Credit Card Numbers Designed: Kurt Saik 05/04/1999 ====================== */ function CreditCardNumbers(vField){ if (vField.value.length <= 16){ if (vField.value.length >= 1){ re = /[A-Za-z]/ if ( re.test(vField.value)){ return (false); } } } return (true); } // /* ====================== Purpose: To validate GE's serial numbers Designed: Kurt Saik 05/04/1999 ====================== */ function SerialValues(vField){ if (vField.value.length >= 18){ return false } re = /\d{17}/ if ( !re.test(vField.value)){ return (false); } return (true); } // /* ====================== Purpose: To validate network ids Designed: Kurt Saik 05/19/1999 ====================== */ function IDValues(vField) { var iReturnValue = AllowNotInString(vField.value, gsInvalidNetworkCharacters); if (iReturnValue ==false){ return (false); }else{ return (true); } } // /* ====================== Purpose: To validate cost centre numbers Designed: Kurt Saik 05/19/1999 ====================== */ function CostCentreValues(vField) { if (vField.value.length > 6){ return (false); } re = /\d{6}/ if ( !re.test(vField.value)){ return (false); } return (true); } // /* ====================== Purpose: Test for invalid characters. sRefString contains a list of invalid characters. sInString is the string to test. Designed: Kurt Saik 05/19/1999 ====================== */ function AllowNotInString(sInString, sRefString){ for (iCounter=0; iCounter < sInString.length; iCounter++){ sTempChar = sInString.substring (iCounter, iCounter+1); if (sRefString.indexOf (sTempChar, 0)!=-1){ return (false); } } return (true); } // /* ====================== Purpose: To validate if the user has entered a value that is divisable by incoming increment Designed: Kurt Saik 05/04/1999 ====================== */ function failIncrementsOf(sField, vType, vIncrement){ isAvailable = FieldAvailable(sField); if (isAvailable == true){ vField = eval("document.forms[0]."+ sField); var iReturnValue = AllowNotInString(vField.value, gsInvalidNetworkCharacters); var iIncrement = Number(vIncrement); var vMessage = "Please enter the value in increments of " + vIncrement + "s. i.e. 1" + vIncrement // + " or 1" 2 * iIncrement; str = String(vField.value) var iFieldIncrement = Number(str.substr(-2,2)); var iTopValue = 100; var iNumberOfElements = iTopValue/iIncrement; sStatus=true; for (i=0; i < iNumberOfElements; i++) { iTopValue = iTopValue-iIncrement; if (iFieldIncrement == iTopValue){ sStatus=false; i = iNumberOfElements + 1; } } if (sStatus == true){ alertBox (vField, vMessage, vType ); return ( true ); } } // end if-isAvailable return; } // end if-failIncrementsOf /* ====================== Purpose: To validate min max values of fields Designed: Kurt Saik 05/04/1999 ====================== */ function failMinMax(sField, vType, vMin, vMax){ isAvailable = FieldAvailable(sField); if (isAvailable == true){ sStatus=false; vField = eval("document.forms[0]."+ sField); var iReturnValue = AllowNotInString(vField.value, gsInvalidNetworkCharacters); var vMessage = "Please enter a value greater than " + vMin + " and less than " + vMax if (iReturnValue ==false){ vMessage = "Please, provide a value without the following characters: \r \n " + gsInvalidNetworkCharacters; sStatus=true; }else{ re = /[A-Za-z]/ if (re.test(vField.value)){ sStatus=true; vMessage = "Only numerics are valid. i.e. 0 thru 9" }else{ if (parseInt(vField.value) < vMin){ sStatus=true; vMessage = "Please enter a value greater than equal to " + vMin + " and less than or equal to " + vMax }else{ if (parseInt(vField.value) > vMax){ sStatus=true; vMessage = "Please enter a value less than or equal to " + vMax + " and greater than or equal to " + vMin }else{ if (vField.value == ""){ sStatus=true; vMessage = "Please enter a value greater than or equal to " + vMin + " and less than or equal to " + vMax }else{ sStatus=false; } } } } } if (sStatus == true){ alertBox (vField, vMessage, vType ); return ( true ); } } return; } /* ====================== Purpose: To validate if the field is exposed for javascript validation Designed: Kurt Saik 29/03/1999 ====================== */ function FieldAvailable(sField){ // Does the field pass validation of being exposed to javascript for ( iField = 0; iField < document.forms[0].length; iField++ ) { if(document.forms[0][iField].name == sField){ return true; } } //--end of for // Other wise return false return false; } // end of FieldAvailable() /* ====================== Purpose: To return the field value (or value list) based on the element type Designed: Kurt Saik 29/03/1999 ====================== */ function getFieldValue ( theField, vType ) { theValue = ""; sep = ""; hits = 0; //text is the user-entered value as a string if ( vType == "text" ) return ( trimsp(theField.value) ); //textarea is the user-entered value as a string array of one element if ( vType == "textarea" ) return ( theField[0].value ); //select is an array of selection pointers to an array of strings representing the choices if ( vType == "select" ) { for ( i = 0; i < theField.options.length; i++ ) { if ( theField.options[i].selected ) theValue += theField.options[i].text } return ( theValue ); } //checkboxes & radio buttons are not so simple if ( vType == "checkbox" || vType == "radio" ) { if ( theField.value == null ) { //if we're here, we are validating a radio button or a multi-element checkbox for ( i = 0; i < theField.length; i++ ) { if ( theField[i].checked ) { hits++; if ( hits > 1 ) { sep = "; "; } theValue += sep + theField[i].value; } } } return ( theValue ); } else { //if we are here, must be an ie checkbox, or nn with a one-element checkbox if ( navigator.appName == "Microsoft Internet Explorer" ) { //ie. return some data so we can validate on the server; return ("can't validate on client") } //nn one-element checkbox, see if its checked ... if (theField.checked ) { return ( theField.value ); }else { return ( "" ); } } } /* ====================== Purpose: To prompt users with a message box Designed: Kurt Saik 29/03/1999 ====================== */ function alertBox (vField, vMessage, vType ) { // if we pass a null message, we are doing a multiple validation test. return so we can check other conditions. if ( vMessage == "null" ) return; // otherwise, display the error message alert ( "Field Contains Incorrect Value:\n\n" + vMessage ) // and set focus (plus select the text if a text element) switch(vType ) { case "text": vField.focus(); vField.select(); break; case "radio": break; case "checkbox": break; case "NonEdit": vField.focus(); vField.value = gEditFieldValue; vField.select(); gEditField = false break; case "phone": vField.focus(); vField.value = "(###)###-####" vField.select(); break; case "postal": vField.focus(); vField.value = "A#A#A#" vField.select(); break; case "serial": vField.focus(); vField.value = "#################" vField.select(); break; case "networkID": vField.focus(); vField.select(); break; case "costcentre": vField.focus(); vField.value = "######" vField.select(); break; case "corpcard": vField.focus(); vField.value = "################" vField.select(); break; default : vField.focus(); break; } //--end of switch return; } /* ====================== Purpose: To stop the submit if a field contains a specified value (or value list) or is not available for validation Designed: Kurt Saik 29/03/1999 ====================== */ function failContains( sField, vValue, vMessage, vType ) { isAvailable = FieldAvailable(sField); if (isAvailable == true){ vField = eval("document.forms[0]."+ sField); //get the field value... theValue = getFieldValue (vField, vType); //check argument list to see if we are testing multiple characters... var count = ( failContains.arguments.length == 6 ) ? vValue.length-1 : 0; var value = ( failContains.arguments.length == 6 ) ? vValue.substring(0,1) : vValue; //fail the submit if the field contains the value(s)... for ( i = 0; i <= count; i++) { if ( theValue.indexOf(value) > -1) { if(vMessage!="ignore"){ alertBox ( vField, vMessage, vType ); } return (true); } value = ( count > 0 ) ? vValue.substring(i+1,i+2) : vValue; } //otherwise continue... return (false) } } var WorkAroundCounter = 0; // ============== // Purpose: To compare values captured from the onload event to value // from the onChange event of a single field. // Designed Kurt Saik Apr/01/1999 function CompareFieldValues(vField, vType){ // Does the field pass validation of being exposed to javascript for ( iCounter = 0; iCounter < gFields.length; iCounter++ ) { if(gFields[iCounter][0] == vField.name){ if(vType=="select-one"){ if(gFields[iCounter][1] == vField.selectedIndex){ return false; }else{ // Test for initial zero values, we don't want to show change status // during a new record event. if(gFields[iCounter][1] == 0){ return false; }else{ return true; } } }else{ if(gFields[iCounter][1] == vField.value){ return false; }else{ // Test for initial blank values, we don't want to show change status // during a new record event. if(gFields[iCounter][1] == ""){ return false; }else{ return true; } return true; } } } } return; } // end of CompareFieldValues(vField) function isaPosNum(s) { return (parseInt(s) > 0) } // ========================================================================= // Purpose: to check for vaild email addresses // Designed: Stephen Ritchie 24/10/2000 // ========================================================================= function emailCheck (sField, vMessage, vType) { isAvailable = FieldAvailable(sField); if (isAvailable == true){ vField = eval("document.forms[0]."+ sField); emailStr = getFieldValue (vField, vType); } var emailPat=/^(.+)@(.+)$/ var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]" var validChars="\[^\\s" + specialChars + "\]" var quotedUser="(\"[^\"]*\")" var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/ var atom=validChars + '+' var word="(" + atom + "|" + quotedUser + ")" var userPat=new RegExp("^" + word + "(\\." + word + ")*$") var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$") var matchArray=emailStr.match(emailPat) if (matchArray==null) { alertBox ( vField, vMessage, vType ); return ( true ); } var user=matchArray[1] var domain=matchArray[2] if (user.match(userPat)==null) { alertBox ( vField, vMessage, vType ); return ( true ); } var IPArray=domain.match(ipDomainPat) if (IPArray!=null) { for (var i=1;i<=4;i++) { if (IPArray[i]>255) { alertBox ( vField, vMessage, vType ); return ( true ); } } return true } var domainArray=domain.match(domainPat) if (domainArray==null) { alertBox ( vField, vMessage, vType ); return ( true ); } var atomPat=new RegExp(atom,"g") var domArr=domain.match(atomPat) var len=domArr.length if (domArr[domArr.length-1].length<2 || domArr[domArr.length-1].length>3) { alertBox ( vField, vMessage, vType ); return ( true ); } if (len<2) { alertBox ( vField, vMessage, vType ); return ( true ); } return } // end of function emailCheck // New routines created by Linden ========================================= /* ================================= Purpose: Validates an field containing either null or not available for validation. ================================= */ function ChkIsNull( sField, vType) { // // Is the field available for validation if (FieldAvailable(sField) == true){ vField = eval("document.forms[0]."+ sField); // get the field value... theValue = getFieldValue (vField, vType); // if the field value is null, we fail and return true... if ( theValue == "" ) { return ( true ); } }// end of (FieldAvailable(sField) == true) } // end of ChkIsNull // New routines created by Linden ========================================= /* ================================= Purpose: Validates a field containing zero value. ================================= */ function ChkIsZero( sField, vType) { // // Is the field available for validation if (FieldAvailable(sField) == true){ vField = eval("document.forms[0]."+ sField); // get the field value... theValue = getFieldValue (vField, vType); // if the field value is zero, we fail and return true... if ( theValue == 0 ) { return ( true ); } }// end of (FieldAvailable(sField) == true) } // end of ChkIsZero /* ====================== Purpose: To validate field length is not longer than allowed. ====================== */ function ChkMaxLength( sField, vValue, vType ) { isAvailable = FieldAvailable(sField); if (isAvailable == true){ vField = eval("document.forms[0]."+ sField); // get the field value... theValue = getFieldValue (vField, vType); if (theValue.length > vValue) { return (true) } }// end of (FieldAvailable(sField) == true) } // end of ChkMaxLength /* ====================== Purpose: To validate field length is not shorter than allowed. ====================== */ function ChkMinLength( sField, vValue, vType ) { isAvailable = FieldAvailable(sField); if (isAvailable == true){ vField = eval("document.forms[0]."+ sField); // get the field value... theValue = getFieldValue (vField, vType); if (theValue.length < vValue) { return (true) } }// end of (FieldAvailable(sField) == true) } // end of ChkMinLength /* ====================== Purpose: To validate field values is numeric (0 to 9). ====================== */ function ChkNumeric(sField, vType){ var strValidChars = "0123456789"; var strChar; var blnResult = false; var isAvailable = FieldAvailable(sField); if (isAvailable == true){ vField = eval("document.forms[0]."+ sField); // get the field value... theValue = getFieldValue (vField, vType); for (i = 0; i < theValue.length && blnResult == false; i++) { strChar = theValue.charAt(i); if (strValidChars.indexOf(strChar) == -1) { blnResult = true; } } return (blnResult) }// end of (FieldAvailable(sField) == true) } // end of ChkNumeric /* ====================== Purpose: To validate field values is currency numeric (0 to 9 and .-,). ====================== */ function ChkCurrency(sField, vType){ var strValidChars = "0123456789.-,"; var strChar; var blnResult = false; var isAvailable = FieldAvailable(sField); if (isAvailable == true){ vField = eval("document.forms[0]."+ sField); // get the field value... theValue = getFieldValue (vField, vType); for (i = 0; i < theValue.length && blnResult == false; i++) { strChar = theValue.charAt(i); if (strValidChars.indexOf(strChar) == -1) { blnResult = true; } } return (blnResult); }// end of (FieldAvailable(sField) == true) } // end of ChkCurrency /* ====================== Purpose: To validate field values is numeric (0 to 9 and decimal). ====================== */ function ChkNumDecimal(sField, vType){ var strValidChars = "0123456789."; var strChar; var blnResult = false; var isAvailable = FieldAvailable(sField); if (isAvailable == true){ vField = eval("document.forms[0]."+ sField); // get the field value... theValue = getFieldValue (vField, vType); for (i = 0; i < theValue.length && blnResult == false; i++) { strChar = theValue.charAt(i); if (strValidChars.indexOf(strChar) == -1) { blnResult = true; } } return (blnResult) }// end of (FieldAvailable(sField) == true) } // end of ChkNumDecimal // ========================================================================= // Purpose: to check for vaild email addresses // Designed: Stephen Ritchie 24/10/2000 // ========================================================================= function ChkEmailFormat (sField, vType) { isAvailable = FieldAvailable(sField); if (isAvailable == true){ vField = eval("document.forms[0]."+ sField); emailStr = getFieldValue (vField, vType); } if (emailStr == "") { return ( false ); } var emailPat=/^(.+)@(.+)$/ var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]" var validChars="\[^\\s" + specialChars + "\]" var quotedUser="(\"[^\"]*\")" var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/ var atom=validChars + '+' var word="(" + atom + "|" + quotedUser + ")" var userPat=new RegExp("^" + word + "(\\." + word + ")*$") var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$") var matchArray=emailStr.match(emailPat) if (matchArray==null) { return ( true ); } var user=matchArray[1] var domain=matchArray[2] if (user.match(userPat)==null) { return ( true ); } var IPArray=domain.match(ipDomainPat) if (IPArray!=null) { for (var i=1;i<=4;i++) { if (IPArray[i]>255) { return ( true ); } } return true } var domainArray=domain.match(domainPat) if (domainArray==null) { return ( true ); } var atomPat=new RegExp(atom,"g") var domArr=domain.match(atomPat) var len=domArr.length if (domArr[domArr.length-1].length<2 || domArr[domArr.length-1].length>3) { return ( true ); } if (len<2) { return ( true ); } return } // end of function ChkEmailFormat /* ====================== Purpose: To stop the submit if a field contains a specified value (or value list) or is not available for validation Designed: Kurt Saik 29/03/1999 ====================== */ function ChkContains( sField, vValue, vType ) { isAvailable = FieldAvailable(sField); if (isAvailable == true){ vField = eval("document.forms[0]."+ sField); //get the field value... theValue = getFieldValue (vField, vType); //check argument list to see if we are testing multiple characters... var count = ( ChkContains.arguments.length == 6 ) ? vValue.length-1 : 0; var value = ( ChkContains.arguments.length == 6 ) ? vValue.substring(0,1) : vValue; //fail the submit if the field contains the value(s)... for ( i = 0; i <= count; i++) { if ( theValue.indexOf(value) > -1) { return (true); } value = ( count > 0 ) ? vValue.substring(i+1,i+2) : vValue; } //otherwise continue... return (false) } } // end of function ChkContains /* ====================== Purpose: To stop the submit if any file upload field is empty Designed: Linden Devine 28/08/2003 ====================== */ function ChkFileUpload() { var ec = document.forms[0].elements.length; var element = document.forms[0].elements; for (i= 0; i < ec; i ++) { if(element[i].type=='file') { if(element[i].value =="") return true; } } return false; } // end of function ChkFileUpload /* ====================== Purpose: To evaluate mask types Designed: Linden Devine Sep 19, 2003 ====================== */ function ChkfailMask( sField, vMask, vType ) { isAvailable = FieldAvailable(sField); if (isAvailable == true){ sStatus = ""; vField = eval("document.forms[0]."+ sField); switch(vMask ) { case "editiondate": var sNewValue = ""; sNewValue = getFieldValue (vField, vType); if (sNewValue.length == 7){ re = /\d{4}\/{1}\d{2}/; if ( re.test(sNewValue)){ sStatus =EditionDateValues(vField, vType) } } else{ sStatus = false } break; case "ifiscode": // 000-000000-0000-000000-000000-0000-0000-0000 var sNewValue = ""; sNewValue = getFieldValue (vField, vType); if (sNewValue.length == 44){ // re = /\d{3}[-]\d{6}[-]\d{4}[-]\d{6}[-]\d{6}[-]\d{4}[-]\d{4}[-]\d{4}/; // Modified by DMG July 12 2010 re = /\w{3}[-]\w{6}[-]\w{4}[-]\w{6}[-]\w{6}[-]\w{4}[-]\w{4}[-]\w{4}/; if ( re.test(sNewValue)){ sStatus = true } } else{ sStatus = false } break; case "emailaddr": // Linden.Devine@ontario.ca var sNewValue = ""; sNewValue = getFieldValue (vField, vType); re = /^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$/; if ( re.test(sNewValue)){ sStatus = true } else{ sStatus = false } break; } //--end of switch if (sStatus == false){ return ( true ); } } return; } //--end of function /* ====================== Purpose: To validate editon date values Designed: Linden Devine, Sep 19, 2003 9999/99 ====================== */ function EditionDateValues(vField, vType){ eStatus = ""; var sNewValue = ""; var sNewYear = ""; var sNewMth = ""; sNewValue = getFieldValue (vField, vType); sNewYear = sNewValue.slice(0,4); sNewMth = sNewValue.slice(5,7); if (sNewYear > "1900" ){ if (sNewYear < "2100" ){ if (sNewMth > "00" ){ if (sNewMth < "13" ){ eStatus = true; } else{ eStatus = false } } else{ eStatus = false } } else{ eStatus = false } } else{ eStatus = false } return ( eStatus ); } //--end of function function Chkfilename(sField, vValue) { // posibly not used any longer ************************************************* //check argument list to see if we are testing multiple characters... var count = ( Chkfilename.arguments.length == 6 ) ? vValue.length-1 : 0; var value = ( Chkfilename.arguments.length == 6 ) ? vValue.substring(0,1) : vValue; //fail the submit if the field contains the value(s)... for ( i = 0; i <= count; i++) { if ( sField.indexOf(value) > -1) { return (true); } value = ( count > 0 ) ? vValue.substring(i+1,i+2) : vValue; } } function ChkCharsNotAllowed(sInString, sRefString){ // Test for invalid characters. sRefString contains a list of invalid characters for (iCounter=0; iCounter < sInString.length; iCounter++){ sTempChar = sInString.substring (iCounter, iCounter+1); if (sRefString.indexOf (sTempChar, 0)!=-1){ return (true); } } return (false); } function chkdupkey(tab, key) { // Test for duplicate key value when adding row var url = docurl.slice(0, (addr.lastIndexOf("nsf") + 3)) + "/CheckDups?openform&TAB=" + tab+ "&KEY=" + key; var dW = window.open(url, "popup", "top=60,left=150,resizable=no,scrollbars=no,width=400,height=180"); dW = null; } function ChkSpecChars(sField, sType, sRefString){ // Test for invalid characters. sRefString contains a list of invalid characters var isAvailable = FieldAvailable(sField); if (isAvailable == true){ vField = eval("document.forms[0]."+ sField); // get the field value... theValue = getFieldValue (vField, sType); for (iCounter=0; iCounter < theValue.length; iCounter++){ sTempChar = theValue.substring (iCounter, iCounter+1); if (sRefString.indexOf (sTempChar, 0)!=-1){ return (true); } } return (false); } } function ChkOutputFile(sField, sType,sRefString) { // Test for invalid characters in outputfile attachment file name var isAvailable = FieldAvailable(sField); if (isAvailable == true){ vField = eval("document.forms[0]."+ sField); // get the field value... theValue = getFieldValue (vField, vType); for (iCounter=0; iCounter < theValue.length; iCounter++){ sTempChar = theValue.substring (iCounter, iCounter+1); if (sRefString.indexOf (sTempChar, 0)!=-1){ return (true); } } return (false); }// end of (FieldAvailable(sField) == true) } // end of ChkOutputFile