无法使用equalTo属性匹配密码

时间:2015-06-07 21:57:50

标签: javascript jquery forms validation

我想使用validate.js验证我的表单并匹配密码。我写了以下代码:

$(document).ready(function () {

    $("#signup-form").validate({
        rules: {
            "signup-username": {
                required: true,
                minlength: 2
            },

            "signup-firstname": {
                required: true,
                minlength: 2
            },
        "signup-lastname": {
                required: true,
                minlength: 2
            },
        "signup-email": {
                required: true
            },
        "signup-password1": {
                required: true,
                minlength: 5
            },
        "signup-password2": {
               equalTo: "#signup-password1"
            }

        },
        messages: {
            "signup-username": {
                required: "Please, enter a user name",
                minlength: "Minimum userlength should be 2"
            },
            "signup-firstname": {
                required: "Please, enter your first name",
                minlength: "Minimum firstname length should be 2"
            },
            "signup-lastname": {
                required: "Please, enter your last name",
                minlength: "Minimum lastname length should be 2"
            },
            "signup-email": {
                required: "Please, enter a valid email"
            },
            "signup-password1": {
               required: "Please, enter your password",
               minlength: "Minimum password length should be 5"
            },
             "signup-password1":"Password doesn't match."

        }
        submitHandler: function (form)
        {

            alert("form is submitted successfully.");
        }
    });

});

我是js的新手。为什么不起作用。有时候我想知道在哪里放逗号而哪些不用。请帮帮我。

2 个答案:

答案 0 :(得分:1)

尝试更改:

plone.recipe.zope2instance

...

"signup-password2": {
           equalTo: "#signup-password2"
        }

为:

"signup-password1":"Password doesn't match."

...

"signup-password2": {
           required: true,
           equalTo: "#signup-password1"
        }

Doc
jsfiddle - 验证插件已损坏 another fiddle - 工作正确

答案 1 :(得分:0)

对此库不熟悉,但我认为您的意思是检查signup-password1是否等于"signup-password2": { equalTo: "#signup-password1" } 。所以它应该是这样的:

return ((x) << 24)  & 0xFF000000 |
       ((y) << 16)  & 0x00FFFF00 |
       z            & 0x000000FF;