/* * To change this template, choose Tools | Templates * and open the template in the editor. */ var formValidator={ init:function(settings){ // console.log(settings.rules[0][0]); this.form=settings.form; this.inputColors=settings.inputColors; this.errorColors=settings.errorColors; this.rules=settings.rules; //console.log(this.rules[0]); this.error_display=settings.error_display; this.form=document.forms[settings.form]; this.errors=new Array(); if(!this.form) { alert("Error: could not get Form object "+settings.form); return; } if(this.form.onsubmit) { this.form.old_onsubmit = this.form.onsubmit; this.form.onsubmit=null; } else { this.form.old_onsubmit = null; } this.form.onsubmit=function (){ formValidator.validate_form(); if(formValidator.errors.length>0){ if(settings.beforeErrorsDisplay){ settings.beforeErrorsDisplay(); } formValidator.display_errors(); return false; } return true; }; //document.form_validator=this; } //validates form , validate_form:function(){ this.clear_errors(); //console.log(this.rules,'r'); for(i=0;i0){ for(var k=0;k@,;:\/]+@\w[\w\.-]+\.[a-z]{2,}$/i return re.test(str); } // returns true if the string only contains characters 0-9 and is not null function isNumeric(str){ if(isRequired(str)) return false; var re = /[\D]/g if (re.test(str)) return false; return true; } //returns true if the length of a string less than max length function isLessThanMaxLength(str,maxLen){ if(!isRequired(str)) return str.length<=maxLen; } //returns true if the length of a string greater than min length function isMoreThanMinLength(str,minLen){ if(!isRequired(str)) return str.length>=minLen; } //returns true if the value of a decimal is greater than the maximum value function isLessThanMaxValue(val,maxVal){ return valminVal; } //returns true if the value of the select is not selected function isValueNotSelected(val,noselect){ //if(obj[obj.selectedIndex].value==noselect) // return false; return !(val==noselect); } //return true if the number of selected items is less than max function isLessThanMax(obj,max){ var count=countSelectedValues(obj); return count<=max; } function countSelectedValues(obj){ var count=0; if( obj.length>0){ for(var i=0;i=min; } function isLessEntry(element,max){ var count=countEntries(element); return count<=max; } function isMoreEntry(element,max){ var count=countEntries(element); return count>=max; } function countEntries(element){ var entries=jQuery('div#tagsdiv-'+element+' div#'+element+' div.tagchecklist span'); return entries.length; } //Error Message class function ErrorMessage(field,message){ this.field=field; this.message=message; } // function isArray(obj) { if (obj.constructor.toString().indexOf("Array") == -1) return false; else return true; }