灵活好用的jq表单验证,自己封装可按照验证需求添加验证方法,不需要修改验证整体结构,内含使用说明。
var arr = new Array();
/*
*/
//用户验证
arr[0] = new XQValidation();
arr[0].XChecksetcont("3-12长度,字母,数字,下划线", "", "表单不能为空", "验证失败", "此用户已存在", "此用户可以注册");
arr[0].posturl("/FormValidation/ajax/ajax-validation.asmx/user_isNull", "name");
arr[0].check("tname", "td1", "checkusername", true, true);
//密码验证
arr[1] = new XQValidation();
arr[1].XChecksetcont("6-20长度,字母,数字,和其他符号", "ok", "表单不能为空", "wrong", "表单不能为空");
arr[1].check("tpass", "td2", "checkpassword", true, false);
//邮箱验证
arr[2] = new XQValidation();
arr[2].XChecksetcont("正确邮箱", "ok", "表单不能为空", "wrong");
arr[2].check("tmail", "td3", "checkemail", true, false);
//联系方式验证
arr[3] = new XQValidation();
arr[3].XChecksetcont("正确手机,非必须", "ok", "表单不能为空", "wrong");
arr[3].check("tmobile", "td4", "checkcontactway", true, false);
//QQ验证
arr[4] = new XQValidation();
arr[4].XChecksetcont("qq,非必须", "ok", "表单不能为空", "wrong");
arr[4].check("tqq", "td5", "checkqq", false, false);
//验证码验证
arr[5] = new XQValidation();
arr[5].XChecksetcont("", "ok", "表单不能为空", "wrong");
arr[5].check("tcode", "td6", "checknull", true, false);
//重复密码验证
arr[6] = new XQValidation();
arr[6].XChecksetcont("", "", "表单不能为空", "密码不匹配");
arr[6].check("tapass", "td7", "checkpassword_", true, false);
/*
*summary:提交表单验证
*/
function formok() {
for (var i = 0; i < arr.length; i++) {//循环遍历验证对象
if (!arr[i].getstate()) {
arr[i].alertwrong();
return false
}
}
//判断两次输入的密码是否一样
if (!chkapass($("tapass").value)) {
arr[6].alertwrong();
return false;
}
return true;
}