⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 full-validator.js

📁 人力资源管理系统
💻 JS
📖 第 1 页 / 共 3 页
字号:
				else this.panel.injectAfter(this.element);			}			return this.panel;		},		validate : function(){			if(this.element.disabled) return true;			var ops = this.options;			this.value = this.getValue();			if(!(this.$value != undefined && this.value == this.$value)){				if(ops.depend){try{eval(ops.depend);}catch(e){alert(e);}};				this.isValid = !ops.require && this.value == '';				if(!this.isValid){						this.$json = null;						this.isValid = this.process();						if(this.isValid && this.isRemote()) this.remoteValidate();				}			}			this.$value = this.value;			this.isValid ? this.success() : this.failure();			return this.isValid;		},		isRemote : function(){			return this.options.action && this.options.action != '';		},		process : function(){			return false;		},		toBoolean : function(i){			return i === true || i === false ? i : 'no,0,false'.indexOf(i.toString().toLowerCase()) == -1;		}	});	ns.RegexElement = new Class({		Extends : AbstractElement,		options : {			pattern : null,			options : ''		},		process : function(){			this.pattern = this.options.pattern && new RegExp(this.options.pattern, this.options.options) || $regexs[this.options.rule];			return this.pattern != null && this.pattern.test(this.value);		}	});		ns.PasswordElement = new Class({		Extends : AbstractElement,		options : {			level : 2/*,			onLevelChange : $empty*/		},		initialize : function(options){			arguments.callee.parent(options);			this.element.addEvent('keyup', this.checkLevel.bind(this));			this.level = 0;		},		checkLevel : function(){			this.value = this.getValue();			this.getLevel();		},		getLevel : function(){			var v = this.value, l = v.length, min = 6, level = 0;			if(l < min){				if(l > 0)	level = 1;			} else {				if(/^(\d{6,9}|[a-z]{6,9}|[A-Z]{6,9})$/.test(v)) level = 1;				else if(/^[^a-z\d]{6,8}$/i.test(v) || !/^(\d{6,9}|[a-z]{6,9}|[A-Z]{6,9})$/.test(v)) level = 2;				if(!/^(([A-Z]*|[a-z]*|\d*|[-_\~!@#\$%\^&\*\.\(\)\[\]\{\}<>\?\\\/\'\"]*)|.{0,5})$|\s/.test(v)) level = l < 10 ? 3 : 4;			}			if(this.leve != level) this.fireEvent('onLevelChange', [level, this]);			return this.level = level;		},		process : function(){			return this.getLevel() >= this.options.level;		}	});		ns.RangeElement = new Class({		Extends : AbstractElement,		options : {			min : 0,			minElement : null,			max : 1000,			maxElement : null,			format : 'yyyy-MM-dd',			as : 'number'		},		types : {			string : function(){this.options.format = null;this.min = this.options.min;this.max = this.options.max;},			caseinsensitivestring : function(){this.value = this.value.toUpperCase();this.min = this.options.min.toUpperCase();this.max = this.options.max.toUpperCase();},			number : function(){this.value = this.value*1;this.min = this.options.min*1;this.max = this.options.max * 1;},			datetime : function(){this.value = ns.isDateTime.call(this.value, this.options.format, true);this.min = ns.isDateTime.call(this.options.min, this.options.format, true);this.max = ns.isDateTime.call(this.options.max, this.options.format, true);},			ip : function(){this.value = util.ipFix(this.value);this.min = util.ipFix(this.options.min);this.max = util.ipFix(this.options.max);}		},		process : function(){			var ops = this.options;			if(ops.minElement != null) ops.min = $(ops.minElement).value;			if(ops.maxElement != null) ops.max = $(ops.maxElement).value;			this.types[ops.as.toLowerCase()].call(this);			return (this.value === false || this.min === false || this.max === false) ? false : this.min <= this.value && this.value <= this.max;		}	});		ns.IdCardElement = new Class({		Extends : AbstractElement,		options : {			length : 'both'		},		process : function(){			if(this.options.length == 18 && 18 != this.value.length) return false;			var number = this.value.toLowerCase();			var d, sum = 0, v = '10x98765432', w = [7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2], a = '11,12,13,14,15,21,22,23,31,32,33,34,35,36,37,41,42,43,44,45,46,50,51,52,53,54,61,62,63,64,65,71,81,82,91';			var re = number.match(/^(\d{2})\d{4}(((\d{2})(\d{2})(\d{2})(\d{3}))|((\d{4})(\d{2})(\d{2})(\d{3}[x\d])))$/);			if(re == null || a.indexOf(re[1]) < 0) return false;			if(re[2].length == 9){				number = number.substr(0, 6) + '19' + number.substr(6);				d = ['19' + re[4], re[5], re[6]].join('-');							} else d = [re[9], re[10], re[11]].join('-');			if(!ns.isDateTime.call(d, 'yyyy-MM-dd')) return false;			for(var i = 0;i < 17; i++) sum += number.charAt(i) * w[i];			return (re[2].length == 9 || number.charAt(17) == v.charAt(sum % 11));		}	});	ns.RepeatElement = new Class({		Extends : AbstractElement,		options : {			to : null		},		process : function(){			return this.options.to && this.value == $(this.options.to).value;		}	});	ns.DateTimeElement = ns.DateElement = ns.TimeElement = new Class({		Extends : AbstractElement,		options : {			format : 'yyyy-MM-dd'		},		process : function(){			return ns.isDateTime.call(this.value, this.options.format);		}	});	ns.GroupElement = new Class({		Extends : ns.RangeElement,		options : {			as : 'number',			elements : '',			iterates : [],			prop : ''		},		attach  : function(validateOnBlur){			arguments.callee.parent(validateOnBlur);			var ops = this.options;			if(ops.elements) {				ops.iterates = $$(ops.elements.split(util.comma).join(',').replace(/\b([^\b#,]+)/g, '#$1'));				if(!ops.prop) ops.prop = 'value';			}			else {				if(this.element.options) {					ops.iterates = this.element.options;					if(!ops.prop) ops.prop = 'selected';				}				else {					ops.iterates = document.getElementsByName(ops['for']);					if(!ops.prop) ops.prop = 'checked';				}			}			if(!validateOnBlur)return;			if(this.element.getTag() != 'input')return;			for(var i = ops.iterates.length - 2; i > -1; i --) $(ops.iterates[i]).addEvents(this.bound);					},		getValue : function(){			var count = 0, ops = this.options;			for(var i = ops.iterates.length - 1; i > -1; i --){				if(ops.iterates[i][ops.prop]) count ++;			}			return count;		}	});	ns.LimitElement = new Class({		Extends : ns.RangeElement,		options : {as : 'number'},		getValue : function(){			return arguments.callee.parent().length;		}	});		ns.LimitBElement = new Class({		Extends : ns.RangeElement,		options : {as : 'number'},		getValue : function(){			return arguments.callee.parent().replace(/[^\x00-\xff]/g,"**").length;		}	});		ns.FilterElement = new Class({		Extends : AbstractElement,		options : {			accept : null,			as : 'file'		},		types : {			file : function(){				return this.options.accept != null && new RegExp("^.+\\.(?=EXT)(EXT)$".replace(/EXT/g, this.options.accept.split(util.comma).join("|")), "gi").test(this.value);			},			badword : function(){				return !this.types.keyword.call(this);			},			keyword : function(){				return this.options.accept != null && new RegExp(this.options.accept.split(util.comma).join("|"), "gi").test(this.value);			},			beginwith : function(){				return this.options.accept != null && new RegExp("^(?=EXT)(EXT)".replace(/EXT/g, this.options.accept.split(util.comma).join("|")), "gi").test(value);			},			endwith : function(){				return this.options.accept != null && new RegExp(".*(?=EXT)(EXT)$".replace(/EXT/g, this.options.accept.split(util.comma).join("|")), "gi").test(value);			}		},		process : function(){			return this.types[this.options.as.toLowerCase()].call(this);		}	});	ns.CustomElement = new Class({		Extends : AbstractElement,		options : {			as : 'regex'		},		initialize : function(options){			arguments.callee.parent(options);			if(this.options.as.toLowerCase() == 'elements') this.init();		},		types : {			regex : function(){				var reVal = false;				try{					reVal = new RegExp(this.options.regex, this.options.options).test(this.value);				} catch(e) { reVal = false;alert(['\u6b63\u5219\u8868\u8fbe\u5f0f\u9519\u8bef\uff1a', e.description].join('\n'));}				return reVal;			},			script : function(){				var reVal = false;				try{					eval(this.options.code);				} catch(e){ reVal = false;alert(['\u81ea\u5b9a\u4e49\u811a\u672c\u9519\u8bef\uff1a', e.description].join('\n'));}				return reVal;			},			elements : function(){				var result = this.expression;				for(var i = this.elements.length - 1; i > -1; i--){					result = result.replace(new RegExp('\\{' + i + '\\}', 'g'), this.elements[i].validate());				}				return eval(result);			}		},		init : function(){			var ops = this.options, elements = ops.expression.split(/[^a-z\d]+/ig).sort();			this.expression = ops.expression;			delete ops.elements;			this.elements = [];			for(var i = 0, l = elements.length; i < l; i ++){				if(i > 0 && elements[i] == elements[i-1]) continue;				var o = {}, e;				for(e in ops){if(typeof(ops[e]) == "string")o[e] = ops[e];}				o.rule = elements[i];				this.elements.push(ns.Factory.Element.build(o));				this.expression = this.expression.replace(new RegExp(elements[i], "gi"), '{' + (this.elements.length - 1) + '}');			}		},		process : function(){			return this.types[this.options.as.toLowerCase()].call(this);		}	});	ns.CompareElement = new Class({		Extends : AbstractElement,		options : {			to : null,			toElement : null,			format : 'yyyy-MM-dd',			as : 'number',			operator : 'equal'		},		types : {			string : function(){this.options.format = null;this.to = this.options.to;},			caseinsensitivestring : function(){this.value = this.value.toUpperCase();this.to = this.options.to.toUpperCase();},			number : function(){this.value = this.value*1;this.to = this.options.to*1},			datetime : function(){this.value = ns.isDateTime.call(this.value, this.options.format, true);this.to = ns.isDateTime.call(this.options.to, this.options.format, true);},			ip : function(){this.value = util.ipFix(this.value);this.to = util.ipFix(this.options.to);}		},		operators : {			notequal : function(){return this.value != this.to;},			greaterthan : function(){return this.value > this.to;},			greaterthanequal : function(){return this.value >= this.to;},			lessthan : function(){return this.value < this.to;},			lessthanequal : function(){return this.value <= this.to;},			equal : function(){return this.value == this.to;}		},		process : function(){			if(this.options.toElement != null) this.options.to = $(this.options.toElement).value;			this.types[this.options.as.toLowerCase()].call(this);			return !(this.value === false || this.to === false) && this.operators[this.options.operator.toLowerCase()].call(this);		}	});	ns.ExtendElements = {};	ns.ExtendMessengers = {};	ns.ExtendReaders = {};	})(window);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -