validate jquery怎么判断一个表单是否通过验证
发布网友
发布时间:2022-04-22 08:26
我来回答
共2个回答
热心网友
时间:2022-04-14 05:11
validate jquery判断一个表单是否通过验证的方法是看页面是否发生跳转。
如果通过验证那么跳转页面,否则停留在原页面进行提示错误。
<html>
<head>
<title></title>
<script src="../Scripts/jquery-1.4.1.min.js" type="text/javascript"></script>
<script src="../Scripts/jquery.validate.js" type="text/javascript"></script>
<script src="../Scripts/jquery.metadata.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function () {
//validate自定义验证
jQuery.validator.addMethod("isZipCode", function (value, element) {
var tel = /^[0-9]{6}$/;
return this.optional(element) || (tel.test(value));
}, "请正确填写您的邮政编码");
$("#signupForm").validate({
rules: {
firstname: "required",
ybno: {
isZipCode: true
},
email: {
required: true, //表示不得为空
email: true //自带邮箱验证
},
password: {
required: true,
minlength: 5 //自带判断字符最小长度
},
confirm_password: {
required: true,
minlength: 5,
equalTo: "#password"
//自带判断当前文本框值与指定ID为password的文本框的值是否相同
}
},
messages: {
firstname: "请输入姓名",
email: {
required: "请输入Email地址",
email: "请输入正确的email地址"
},
password: {
required: "请输入密码",
minlength: jQuery.format("密码不能小于{0}个字符")
},
confirm_password: {
required: "请输入确认密码",
minlength: "确认密码不能小于5个字符",
equalTo: "两次输入密码不一致不一致"
}
}
});
});
</script>
//错误提示信息的样式
<style type="text/css">
label.error{color: Red;padding-left: 20px; border:1px solid #006655; margin-left:10px;
padding-left:0px; font-size:12px;}
input.error{border: solid 1px red;}
</style>
</head>
<body>
<form id="signupForm" method="get" action="">
<p>
<label for="firstname">Firstname</label>
<input id="firstname" name="firstname" />
</p>
<p>
<label for="ybno">邮编</label>
<input id="ybno" name="ybno" />
</p>
<p>
<label for="email">E-Mail</label>
<input id="email" name="email" />
</p>
<p>
<label for="password">Password</label>
<input id="password" name="password" type="password" />
</p>
<p>
<label for="confirm_password">确认密码</label>
<input id="confirm_password" name="confirm_password" type="password" />
</p>
<p>
热心网友
时间:2022-04-14 06:29
判断一个表