时间:2021-07-01 10:21:17 帮助过:7人阅读
<!doctype html>
<html>
<head>
<title>表单验证的完整应用</title>
<style type="text/css">
.leftside{width:100px; text-align:right;float:left;}
label.error{color:#ea5200; margin-left:4px; padding:0px 20px; background:url(http://jt.875.cn/icon/unchecked.gif) no-repeat 2px 0 }
label.right{margin-left:4px; padding-left:20px; background:url(http://jt.875.cn/icon/checked.gif) no-repeat 2px 0}
</style>
<script type="text/javascript" src="http://jt.875.cn/js/jquery.js"></script>
<script type="text/javascript" src="http://jt.875.cn/js/jquery.validate.js"></script>
<script type="text/javascript">
$(function(){
$( "#regForm" ).validate({
rules: {
// 注册用户名
username: {
required: true,
minlength: 5,
maxlength: 12
},
email: {
required: true,
email: true
},
// 密码
password: {
required: true,
minlength: 6,
maxlength: 18
},
// 确认密码
confirm_password: {
equalTo:"#password"
},
// 检验验证码
captcha: {
required: true,
remote: "checkCaptcha.php"
}
},
messages: {
// 注册用户名
username: {
required: "此项不能为空",
minlength: "不能少于5个字符",
maxlength: "不能多于12个字符"
},
email: {
required: "此项不能为空",
email: "email格式不正确"
},
// 密码
password: {
required: "此项不能为空",
minlength: "不能少于6个字符",
maxlength: "不能多于18个字符"
},
// 确认密码
confirm_password: "两次输入密码不一致",
// 检验验证码
captcha: {
required: "请输入验证码",
remote: "验证码输入错误"
}
}
});
});
</script>
</head>
<body>
<form id="regForm" method="get" action="">
<p><label class="leftside">姓名:</label><input type="text" value="" name="username" id="username" /></p>
<p><label class="leftside">密码:</label><input type="password" value="" name="password" id="password" /></p>
<p><label class="leftside">确认密码:</label><input type="password" value="" name="confirm_password" id="confirm_password" /></p>
<p><label class="leftside">EMAIL:</label><input type="text" value="" name="email" id="email" /></p>
</form>
</body>
</html>
效果图如下