使用jQuery Validate验证两个字段

我正在使用jQuery Validate Plugin:
http://bassistance.de/jquery-plugins/jquery-plugin-validation/

简单演示:

<input type="text" name="email" class="required email" />
  <input type="text" name="email_confirm" class="required email" />

如何检查两个输入中的值是否与jQuery或jQuery Validate Plugin相同.

我只是尝试了相同,它的工作原理:

rules: {
  email: 'required',email2: {equalTo: '.email'}

解决方法

通过查看 http://jquery.bassistance.de/validate/demo/的演示页面,您可以使用“equalTo”验证两个应该相等的字段:

$("#signupForm").validate({
    rules: {
                    ...snip... 
        password: {
            required: true,minlength: 5
        },confirm_password: {
            required: true,minlength: 5,equalTo: "#password"
        },...snip...
    },messages: {
        ...snip...
        password: {
            required: "Please provide a password",minlength: "Your password must be at least 5 characters long"
        },confirm_password: {
            required: "Please provide a password",minlength: "Your password must be at least 5 characters long",equalTo: "Please enter the same password as above"
        },...snip...
    }
});

要使用类方法,只需要找到语法.我找不到equalTo属性,但它可能是这样的:

class="required email equalTo['email']"

相关文章

页面搜索关键词突出 // 页面搜索关键词突出 $(function () {...
jQuery实时显示日期、时间 html: &lt;span id=&quot...
jQuery 添加水印 &lt;script src=&quot;../../../.....
中文:Sys.WebForms.PageRequestManagerParserErrorExceptio...
1. 用Response.Write方法 代码如下: Response.Write(&q...
Jquery实现按钮点击遮罩加载,处理完后恢复 思路: 1.点击按...