//To check whether the Textbox control is blank or not function IsInputFilled(strControl) { if(strControl.value=="") { return false; } else { return true; } } //To check whether the Dropdown control is selected or not function IsSelectFilled(strControl) { if(strControl.selectedIndex < 0) { return false; } if(strControl[strControl.selectedIndex].value=="") { return false; } else { return true; } } //To check whether the Radio control is selected or not function IsRadioFilled(strControl) { for(i=0; i 1)) { return false; } else { return true; }*/ var str; if(strControl.type) { // assuming every form variable will have 'type'. str = strControl.value; } else { // plain value sent instead of control name str = strControl; } var remove_comma=/\,/g; str=str.replace(remove_comma, ''); var remove_minus=/^-/g; str=str.replace(remove_minus, ''); var filter=/[0-9]*[.][0-9]*[.][0-9]*/ //[^0-9.] will match for strings other than 0 to 9 and dot. var filter1=/[^0-9.]/ if ((filter.test(str)==true)||(filter1.test(str)==true)) { return false; } else { return true; } } function IsCurrency(strControl) { if(!IsFloat(strControl)) { return false; } var t = parseFloat(strControl.value) * 100; t = "" + t; if(t.indexOf('.') >=0 ) { return false; } return true; } //To check whether the Email Id entered in Textbox control is valid Email Id or not function IsEmail(strControl) { var str; if(strControl.type) { // assuming every form variable will have 'type'. str = strControl.value; } else { // plain value sent instead of control name str = strControl; } if(str=="") { return true; } //var filter=/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/ //var filter = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/ var filter = /^(([^<>()[\]\\.,;:\s@\!$#&%*?~`^{}'|+="]+(\.[^<>()[\]\\.,;:\s@\!$#&%*?~`^{}'|+="]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/ str = str.replace(/[ |,|;]/g, ","); str = str.replace(/,,/g, ","); var ArrayOfEmailIds = str.split(/[\s,;]/); // alert(ArrayOfEmailIds.length); for(i=0; i 3)) { return false; } /*else if(LibIsValidInteger(day)==false||LibIsValidInteger(month)==false||LibIsValidInteger(year)==false) { return false; }*/ var filter=/[^0-9]/ if (filter.test(day)==true) { return false; } if (filter.test(month)==true) { return false; } if (filter.test(year)==true) { return false; } if((day <= 0)||(day > 31)) { return false; } if((month <= 0)||(month > 12)) { return false; } if(((month == 4)||(month == 6)||(month == 9)||(month == 11))&&(day == 31)) { return false; } if(month==2) { var isLeapYear =(year % 4==0 &&(year % 100 !=0||year % 400 ==0)); //alert(isLeapYear); if(day > 29 || (day == 29 && !isLeapYear)) { return false; } } if((year.length==3)||(year.length > 4)||(year.length==0)) { return false } else { return true; } } //It checks whether the time is in valid hh:mm:ss format or not function IsTime(strControl) { var str; if(strControl.type) { // assuming every form variable will have 'type'. str = strControl.value; } else { // plain value sent instead of control name str = strControl; } if(str == "") { return true; // Note, mandatory validations are anyways separately done. } var timeSplit=strControl.value.split(":") var hours = timeSplit[0]; var minutes = timeSplit[1]; var seconds = timeSplit[2]; if((timeSplit.length < 3)||(timeSplit.length > 3)) { return false; } var filter=/[^0-9]/ if (filter.test(hours)==true) { return false; } if (filter.test(minutes)==true) { return false; } if (filter.test(seconds)==true) { return false; } if((hours < 0)||(hours> 23)) { return false; } if((minutes< 0)||(minutes> 59)) { return false; } if((seconds< 0)||(seconds> 59)) { return false; } if(hours.length!=2) { return false; } if(minutes.length!=2) { return false; } if(seconds.length!=2) { return false; } return true; } function IsDatetime(strControl) { var str; if(strControl.type) { // assuming every form variable will have 'type'. str = strControl.value; } else { // plain value sent instead of control name str = strControl; } if(str == "") { return true; // Note, mandatory validations are anyways separately done. } if(strControl.value.indexOf(" ")==-1) { return false; } var space=strControl.value.split(" "); var date = space[0]; /*if(LibIsValidDate(date)==false) { return false; }*/ var dateSplit= date.split("/"); var time = space[1] var timeSplit = time.split(":") if((dateSplit.length < 3)||(dateSplit.length > 3)) { return false; } if((timeSplit.length < 3)||(timeSplit.length > 3)) { return false; } var month = dateSplit[1]; var day = dateSplit[0]; var year = dateSplit[2]; /*var now = new Date() var hour = now.getHours(); var min = now.getMinutes(); var sec = now.getSeconds();*/ var hour = timeSplit[0]; var min = timeSplit[1]; var sec = timeSplit[2]; if((day <= 0)||(day > 31)) { return false; } if((month <= 0)||(month > 12)) { return false; } if(((month == 4)||(month == 6)||(month == 9)||(month == 11))&&(day == 31)) { return false; } if(month==2) { var isLeapYear =(year % 4==0 &&(year % 100 !=0||year % 400 ==0)); //alert(isLeapYear); if(day > 29 || (day == 29 && !isLeapYear)) { return false; } } if((year.length==3)||(year.length > 4)||(year.length==0)) { return false } if((hour < 0)||(hour >=24)) { return false; } if((min < 0)||(min >=60)||(min=="")) { return false; } if((sec < 0)||(sec >=60)||(sec=="")) { return false; } /*else { strControl.value = day + "/" + month + "/" + year + " " + hour + ":" + min + ":" + sec }*/ return true; } function InputError(strControl,strMessage) { if(strMessage=="") { if(document.getElementById('vld'+strControl.name)) { eval("document.getElementById('vld"+strControl.name+"').innerHTML = '';"); } return; } if(document.getElementById('vld'+strControl.name)) { eval("document.getElementById('vld"+strControl.name+"').innerHTML = '"+strMessage+"';"); } else { MyAlert(strMessage); } strControl.focus(); strControl.select(); } function SelectError(strControl,strMessage) { MyAlert(strMessage); strControl.focus(); } //it checks whether the To Date is later than or equal-to From Date function FromDateSmaller(strControl,strControl1) { var fromDate=strControl.value; var toDate=strControl1.value; var testdate = new Date(fromDate.substring(6,10),fromDate.substring(3,5)-1,fromDate.substring(0,2)); var testdate1 = new Date(toDate.substring(6,10),toDate.substring(3,5)-1,toDate.substring(0,2)); if(testdate=="NaN" || testdate1=="NaN") { return true; } if(testdate > testdate1) { return false; } return true; } //it checks whether the To Time is later than or equal-to From Time function FromTimeSmaller(strControl,strControl1) { var t1=strControl.value; var t2=strControl1.value; var re=/:/g; t1=t1.replace(re, ""); t2=t2.replace(re, ""); if(t1>t2) { return false; } return true; } //it checks whether the from Value is less than to Value function LibValueComparison(strControl,strControl1) { if(strControl.value >= strControl1.value) { return false; } else { return true; } } function FieldHelp(strTable,strField,strHeight,strWidth) { var helpWindow=window.open('Help/Field/'+strTable +'_' +strField +'.aspx','FieldHelp','height='+strHeight+',width='+strWidth+',left=660,top=205') helpWindow.focus(); } var ValidationError = false; var TheLastErroneousField=false; function AllAddModifyValid(PageObject=false) { ValidationError = false; var fieldname; TheLastErroneousField=false; if(PageObject==false) { // Backward compat. w/o CompositePages - ONE form per page. var Mandatory = AllMandatory.split(","); var tMandatory = ","+AllMandatory+","; var tIntegers = ","+AllIntegers+","; var tFloats = ","+AllFloats+","; var tStrings = ","+AllStrings+","; var tCurrencies = ","+AllCurrencies+","; var tEmails = ","+AllEmails+","; var tDates = ","+AllDates+","; var tDateTimes = ","+AllDateTimes+","; } else { var Mandatory = PageObject.AllMandatory.split(","); var tMandatory = ","+PageObject.AllMandatory+","; var tIntegers = ","+PageObject.AllIntegers+","; var tFloats = ","+PageObject.AllFloats+","; var tStrings = ","+PageObject.AllStrings+","; var tCurrencies = ","+PageObject.AllCurrencies+","; var tEmails = ","+PageObject.AllEmails+","; var tDates = ","+PageObject.AllDates+","; var tDateTimes = ","+PageObject.AllDateTimes+","; if(typeof(PageObject.objForm)!='undefined') { objForm=PageObject.objForm; } } for(iFormElements = objForm.elements.length-1; iFormElements>=0; iFormElements--) { // why this logic? ...because error sequence should be same as physical sequence on screen. var Field = objForm.elements[iFormElements]; // alert(Field.name); if(!Field.name || !Field.type) { // Some elements may not be "Fields" at all. continue; } if(!eval("document.getElementById('vld"+Field.name+"')")) { // Hidden fields have no vld** div continue; } if(tMandatory.indexOf(","+Field.name+",") != -1) { if(!MandatoryValid(Field)) { ValidationError = true; TheLastErroneousField = Field; continue; // If primary validation fails, why go to next one! } } var vldMessageContainer=objForm.querySelector("#vld"+Field.name); if(tStrings.indexOf(","+Field.name+",") != -1) { if(!IsString(Field)) { eval("vldMessageContainer.innerHTML = 'Contains Invalid Characters';"); TheLastErroneousField = Field; Field.focus(); ValidationError = true; } else { eval("vldMessageContainer.innerHTML = '';"); } } if(tIntegers.indexOf(","+Field.name+",") != -1) { if(!IsInteger(Field)) { eval("vldMessageContainer.innerHTML = 'Should be Whole Number';"); Field.focus(); ValidationError = true; } else { eval("vldMessageContainer.innerHTML = '';"); } } if(tFloats.indexOf(","+Field.name+",") != -1) { if(!IsFloat(Field)) { eval("vldMessageContainer.innerHTML = 'Should be Decimal Number';"); Field.focus(); ValidationError = true; } else { eval("vldMessageContainer.innerHTML = '';"); } } if(tCurrencies.indexOf(","+Field.name+",") != -1) { if(!IsCurrency(Field)) { eval("vldMessageContainer.innerHTML = 'Should be Decimal with max 2 decimal places';"); Field.focus(); ValidationError = true; } else { eval("vldMessageContainer.innerHTML = '';"); } } if(tEmails.indexOf(","+Field.name+",") != -1) { if(!IsEmail(Field)) { eval("vldMessageContainer.innerHTML = 'Should be of the form x@y.z';"); Field.focus(); ValidationError = true; } else { eval("vldMessageContainer.innerHTML = '';"); } } if(tDates.indexOf(","+Field.name+",") != -1) { if(!IsDate(Field)) { eval("vldMessageContainer.innerHTML = 'Should be a valid Date';"); Field.focus(); ValidationError = true; } else { eval("vldMessageContainer.innerHTML = '';"); } } if(tDateTimes.indexOf(","+Field.name+",") != -1) { if(!IsDatetime(Field)) { eval("vldMessageContainer.innerHTML = 'Should be a valid DateTime';"); Field.focus(); ValidationError = true; } else { eval("vldMessageContainer.innerHTML = '';"); } } } if(TheLastErroneousField!=null) { FindParentTabAndFocus(TheLastErroneousField); window.setTimeout("TheLastErroneousField.focus();", 2000); } return !ValidationError; } function AllAddModifyManyValid() { ValidationError = false; var MyMandatory = AllMandatory.split(","); var MyIntegers = AllIntegers.split(","); var MyFloats = AllFloats.split(","); var MyStrings = AllStrings.split(","); var MyCurrencies = AllCurrencies.split(","); var MyEmails = AllEmails.split(","); var MyDates = AllDates.split(","); var MyDateTimes = AllDateTimes.split(","); var Field; var TheLastErroneousField=null; var BlankRow = true; var Fields = AllFields.split(","); var t; for(i=0; i < objForm.HowManyEntities.value; i++) { t=""; for(aay=0; aay < Fields.length; aay++) { t += eval("objForm."+Fields[aay]+i+".value"); if(document.getElementById("vld"+Fields[aay]+i)) { document.getElementById("vld"+Fields[aay]+i).innerHTML = ""; } } if(t=="") { // blank row continue; } for(j=0; j < MyMandatory.length; j++) { Field = eval("objForm."+MyMandatory[j]+i); if(!IsInputFilled(Field)) { if(document.getElementById("vld"+MyMandatory[j]+i)) { document.getElementById("vld"+MyMandatory[j]+i).innerHTML = " ! "; } else { MyAlert("Mandatory Field"); TheLastErroneousField = Field; Field.focus(); } ValidationError=true; } } for(j=0; j < MyIntegers.length; j++) { if(MyIntegers[j]=="") { continue; } Field = eval("objForm."+MyIntegers[j]+i); if(!IsInteger(Field)) { if(document.getElementById("vld"+MyIntegers[j]+i)) { document.getElementById("vld"+MyIntegers[j]+i).innerHTML = " ! "; } else { MyAlert("Contains Invalid Characters"); Field.focus(); } ValidationError=true; } } for(j=0; j < MyFloats.length; j++) { if(MyFloats[j]=="") { continue; } Field = eval("objForm."+MyFloats[j]+i); if(!IsFloat(Field)) { if(document.getElementById("vld"+MyFloats[j]+i)) { document.getElementById("vld"+MyFloats[j]+i).innerHTML = " ! "; } else { MyAlert("Contains Invalid Characters"); Field.focus(); } ValidationError=true; } } for(j=0; j < MyStrings.length; j++) { if(MyStrings[j]=="") { continue; } Field = eval("objForm."+MyStrings[j]+i); if(!IsString(Field)) { if(document.getElementById("vld"+MyStrings[j]+i)) { document.getElementById("vld"+MyStrings[j]+i).innerHTML = " ! "; } else { MyAlert("Contains Invalid Characters"); TheLastErroneousField=Field; Field.focus(); } ValidationError=true; } } for(j=0; j < MyCurrencies.length; j++) { if(MyCurrencies[j]=="") { continue; } Field = eval("objForm."+MyCurrencies[j]+i); if(!IsCurrency(Field)) { if(document.getElementById("vld"+MyCurrencies[j]+i)) { document.getElementById("vld"+MyCurrencies[j]+i).innerHTML = " ! "; } else { MyAlert("Contains Invalid Characters"); Field.focus(); } ValidationError=true; } } for(j=0; j < MyEmails.length; j++) { if(MyEmails[j]=="") { continue; } Field = eval("objForm."+MyEmails[j]+i); if(!IsEmail(Field)) { if(document.getElementById("vld"+MyEmails[j]+i)) { document.getElementById("vld"+MyEmails[j]+i).innerHTML = " ! "; } else { MyAlert("Contains Invalid Characters"); Field.focus(); } ValidationError=true; } } for(j=0; j < MyDates.length; j++) { if(MyDates[j]=="") { continue; } Field = eval("objForm."+MyDates[j]+i); if(!IsDate(Field)) { if(document.getElementById("vld"+MyDates[j]+i)) { document.getElementById("vld"+MyDates[j]+i).innerHTML = " ! "; } else { MyAlert("Contains Invalid Characters"); Field.focus(); } ValidationError=true; } } for(j=0; j < MyDateTimes.length; j++) { if(MyDateTimes[j]=="") { continue; } Field = eval("objForm."+MyDateTimes[j]+i); if(!IsDatetime(Field)) { if(document.getElementById("vld"+MyDateTimes[j]+i)) { document.getElementById("vld"+MyDateTimes[j]+i).innerHTML = " ! "; } else { MyAlert("Contains Invalid Characters"); Field.focus(); } ValidationError=true; } } } if(ValidationError) { MyAlert("Some fields have incorrect inputs. Please see messages in front of the fields."); return; } if(TheLastErroneousField) { FindParentTabAndFocus(TheLastErroneousField); window.setTimeout("TheLastErroneousField.focus();", 2000); } return !ValidationError; } function AllSearchValid(PageObject=false) { ValidationError = false; var fieldname; if(PageObject==false) { // Backward compat. w/o CompositePages - ONE form per page. var tAllLists = ","+AllLists+","; var tAllRanges = ","+AllRanges+","; } else { var tAllLists = ","+PageObject.AllLists+","; var tAllRanges = ","+PageObject.AllRanges+","; if(typeof(PageObject.objForm)!='undefined') { objForm=PageObject.objForm; } } for(i = objForm.elements.length-1; i>=0; i--) { // why this logic? ...because error sequence should be same as physical sequence on screen. var Field = objForm.elements[i]; if(!Field.name || !Field.type) { // Some elements may not be "Fields" at all. continue; } if(!eval("document.getElementById('vld"+Field.name+"')")) { // Hidden fields have no vld** div continue; } if(tAllLists.indexOf(Field.name) != -1) { if(Field.value.indexOf("'") != -1 || Field.value.indexOf('"') != -1) { eval("vldMessageContainer.innerHTML = 'Contains Invalid Characters';"); Field.focus(); ValidationError = true; } else { eval("vldMessageContainer.innerHTML = '';"); } } if(tAllRanges.indexOf(Field.name) != -1) { eval("var t1 = document." + Field.form + "." + Field.name + "From;"); eval("var t2 = document." + Field.form + "." + Field.name + "To;"); if( ( IsInputFilled(t1) & !IsInputFilled(t2)) || ( IsInputFilled(t2) & !IsInputFilled(t1)) ) { eval("vldMessageContainer.innerHTML = 'Specify Start as well as End values';"); t1.focus(); ValidationError = true; } else { eval("vldMessageContainer.innerHTML = '';"); } } } return !ValidationError; } function MandatoryValid(Field){ var MValidationError = false; var vldMessageContainer=Field.form.querySelector("#vld"+Field.name); fieldtype = Field.type.toLowerCase(); fieldname = Field.name; if(fieldtype == "text" || fieldtype == "number" || fieldtype == "password" || fieldtype == "hidden" || fieldtype == "textarea") { if(!IsInputFilled(Field)) { eval("vldMessageContainer.innerHTML = 'Mandatory field';"); FindParentTabAndFocus(Field); Field.focus(); MValidationError = true; } else { eval("vldMessageContainer.innerHTML = '';"); } } else if(fieldtype == "checkbox") { if(!IsCheckBoxFilled(Field)) { eval("vldMessageContainer.innerHTML = 'Mandatory field';"); FindParentTabAndFocus(Field); Field.focus(); MValidationError = true; } else { eval("vldMessageContainer.innerHTML = '';"); } } else if(fieldtype == "radio") { if(!IsRadioFilled(Field)) { eval("vldMessageContainer.innerHTML = 'Mandatory field';"); FindParentTabAndFocus(Field); Field.focus(); MValidationError = true; } else { eval("vldMessageContainer.innerHTML = '';"); } } else if(fieldtype.indexOf("select")!=-1) { if(!IsSelectFilled(Field)) { eval("vldMessageContainer.innerHTML = 'Mandatory field';"); FindParentTabAndFocus(Field); Field.focus(); MValidationError = true; } else { eval("vldMessageContainer.innerHTML = '';"); } } else { MyAlert(fieldname + " is a Mandatory field."); FindParentTabAndFocus(Field); Field.focus(); MValidationError = true; } if(MValidationError) { return false; } return true; } function FindParentTabAndFocus(Field) { var t=document.getElementsByClassName('tabbertab'); // This is programming standard of the tab control we are using if(!t || t.length==0) return; // no tabs on this screen. var Parent=Field.parentNode; while(Parent) { if(Parent.nodeName=="DIV" && Parent.classList.contains("tabbertab")) { // alert(Parent.parentNode.tabber); var Tabber = Parent.parentNode; var AllTabs = Tabber.getElementsByTagName("div"); for(var iAllTabs=0; iAllTabs 31 && (charCode < 48 || charCode > 57)){ e.preventDefault(); } //return false; //return true; }); } function onlyFloats(Field) { $('#'+Field.name).keypress(function(event) { if(event.which < 46 || event.which > 59) { event.preventDefault(); } // prevent if not number/dot if(event.which == 46 && $(this).val().indexOf('.') != -1) { event.preventDefault(); } // prevent if already dot }); } function validateOnKeystroke(){ // byepassed ValidationError = false; var Mandatory = AllMandatory.split(","); var fieldname; var tIntegers = ","+AllIntegers+","; var tFloats = ","+AllFloats+","; for(i = objForm.elements.length-1; i>=0; i--) { // why this logic? ...because error sequence should be same as physical sequence on screen. var Field = objForm.elements[i]; if(!Field.name || !Field.type) { // Some elements may not be "Fields" at all. continue; } if(!eval("document.getElementById('vld"+Field.name+"')")) { // Hidden fields have no vld** div continue; } if(tIntegers.indexOf(","+Field.name+",") != -1) { if(onlyIntegers(Field)){ ValidationError = true; } } if(tFloats.indexOf(","+Field.name+",") != -1) { if(onlyFloats(Field)){ ValidationError = true; } } } return !ValidationError; }