一个很强的验证脚本


var Page_ValidationVer = "125"; 
var Page_IsValid = true; 
var Page_BlockSubmit = false; 
var Msg=""; 
///验证入口 
function Page_ClientValidate() 

var i; 
for (i = 0; i < Page_Validators.length; i++) { 
if(!ValidatorValidate(Page_Validators[i])) 

MsgBox(Page_Validators[i]); 
event.returnValue = false; 
return false; 

}


function MsgBox(val) 

if(Msg!="") 

Msg="(错误提示:"+Msg+")"; 

alert(ValidatorErrorMsg(val)+"\r\n"+Msg); 

///单个验证 
function ValidatorValidate(val) { 
var control = ValidatorControl(val.controltovalidate); 
value=ValidatorGetValue(control); 
if(!MaxLength(val.MaxLength,value)) return false; 
flag=true; 
if(value=="") 

control.focus(); 
Msg="文本框不能为空!"; 
return val.AllowNull=="True"; 

var dataType = val.DataType; 
if(dataType=="Empty") 

flag= true; 

else if(dataType =="String") 

flag = IsString(value); 

else if(dataType =="Letter") 

flag = IsLetter(value); 

else if (dataType == "StringInteger") { 
flag= IsStringInteger(value); 

else if (dataType == "Integer") { 
flag= IsInteger(value); 

else if(dataType =="Chinese") 

flag = IsChinese(value); 

else if(dataType =="UnSignIntger") 

flag = IsUnSignIntger(value); 

else if(dataType == "Double") { 
flag = IsDouble(value); 

else if(dataType =="Email") 

flag = IsEmail(value); 

else if(dataType =="IP") 

flag = IsIP(value); 

else if(dataType =="Phone") 

flag = IsPhone(value); 

else if(dataType =="ZIP") 

flag = IsZIP(value); 

else if (dataType == "Currency") { 
flag = IsCurrency(value); 

else if (dataType == "Date") { 
flag = IsDate(value); 

else if(dataType =="Time") 

flag = IsTime(value); 

else if (dataType == "DateTime") { 
flag = IsDateTime(value); 

else 

flag = IsOther(value); 
}

if(flag==false) 

control.focus(); 

return flag; 

///获取验证的错误消息 
function ValidatorErrorMsg(val) 

return val.errormessage; 

///获取控件对象 
function ValidatorControl(id) 

var control; 
control = document.all[id]; 
return control 

function ValidatorGetValue(control) {

if (typeof(control.value) == "string") { 
return control.value; 

if (typeof(control.tagName) == "undefined" && typeof(control.length) == "number") { 
var j; 
for (j=0; j < control.length; j++) { 
var inner = control[j]; 
if (typeof(inner.value) == "string" && (inner.type != "radio" || inner.status == true)) { 
return inner.value; 



else { 
return ValidatorGetValueRecursive(control); 

return ""; 

function ValidatorGetValueRecursive(control) 

if (typeof(control.value) == "string" && (control.type != "radio" || control.status == true)) { 
return control.value; 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值