需要引入jar包
<script type="text/javascript" src="js/jquery-1.10.2.min.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/js/jquery.validate/jquery.validate.min.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/js/jquery.validate/additional-methods.min.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/js/jquery.validate/localization/messages_zh.js"></script>
<form id="savePassWord" method="post">
校验的方法为:
function checkInputPass(){
$("#savePassWord").validate({ //验证的按钮触发
rules: {
"oldpassword": { //name
required: true,
minlength: 3
},
"password": {
required: true,
minlength: 3
},
"surepassword": {
required: true,
equalTo: "#passwordId" //id
}
},
messages: {
"oldpassword": {
required: '原密码不能为空!',
minlength: $.validator.format('原密码不能小于{0}!')
},
"password": {
required: '新密码不能为空!',
minlength: $.validator.format('新密码不能小于{0}!')
},
"surepassword": {
required: '确认新密码不能为空!',
equalTo: '请输入与上面相同的密码!'
}
},
// 错误的位置设置
errorPlacement: function(error, element)
{
error.appendTo($(element).parent().find("span"));
},
// 提交拦截处理,specifying a submitHandler prevents the default submit, good for the demo
submitHandler: function(form)
{ }
});
}