📄 clientvalidate.js
字号:
function a$(iterable){
if (!iterable) return [];
if (iterable.toArray) {
return iterable.toArray();
} else {
var results = [];
for (var i = 0; i < iterable.length; i++)
results.push(iterable[i]);
return results;
}
}
Function.prototype.bind = function() {
var __method = this, args = a$(arguments), object = args.shift();
return function() {
return __method.apply(object, args.concat(a$(arguments)));
}
}
/**/
function elementValidator(element)
{
this._element = element;
this.RegExp = new RegExp(element.getAttribute("RegExp"));
this.InfoEle = document.all(element.getAttribute("InfoId"));
this.InfoHTML = this.InfoEle.innerHTML;
this.InfoCSS = this.InfoEle.className;
this.elementCSS = this._element.className;
this.compareTo = element.getAttribute("compareTo");
if(this.compareTo != null)
{
this.compareTo = document.all(this.compareTo);
}
this.Callback = element.getAttribute("Callback");
this.validate = function(){
var isMatch;
if(this.compareTo != null)
{
isMatch = this._element.value == this.compareTo.value?true:false;
}else
{
isMatch = this.RegExp.test(this._element.value);
}
if(isMatch)
{
if(this.Callback != null)
{
var result = eval(this.Callback+"('"+this._element.value+"')");
if(result != null)
{
isMatch = false;
this.freshUI(result,isMatch);
}else{
this.freshUI(this.InfoHTML,isMatch);
}
}else{
this.freshUI(this.InfoHTML,isMatch);}
}else{
if(this.compareTo != null)
{
this.freshUI(this.InfoEle.getAttribute("errInfo"),isMatch);
}else{
this.freshUI(this.InfoHTML,isMatch);
}
}
return isMatch;
}
this.freshUI = function(info,isMatch){
this.InfoEle.innerHTML = info;
if(isMatch)
{
this.InfoEle.className = this.InfoCSS;
this._element.className = this.elementCSS;
}else{
this.InfoEle.className = this.InfoEle.getAttribute("cssError");
this._element.className = this._element.getAttribute("cssError");
}
}
this._element.attachEvent("onblur",this.validate.bind(this));
}
function clientValidator(form)
{
//待验证表单
this.form = new Object();
//待验证表单元素列表
this.elements = new Array();
this.validate = function(){
for(var i=0;i<this.elements.length;i++)
{
if(this.elements[i].validate() == false)
{
event.returnValue =false;
event.cancalBubble = true;
}
}
}
//setup
this.form = form;
for(var i=0;i<this.form.elements.length;i++)
{
if(this.form.elements[i].getAttribute("InfoId") != null)
{
this.elements[this.elements.length] = new elementValidator(this.form.elements[i]);
}
}
this.form.attachEvent("onsubmit",this.validate.bind(this));
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -