}
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;
}
原文:http://blog.csdn.net/u014739763/article/details/24358611