jquery:密码和确认密码

时间:2013-05-07 04:12:17

标签: c# jquery asp.net

我正在使用文本框的jquery插件..在我的其他文本框中插件工作正常...但是当我提供我的一些文本框的详细信息时,jquery不起作用..

这是我的代码:

    jQuery("#Merchant_Registration").validate({
                rules: {
                    UserN: "required",
                    pass: {
                        required: true,
                        minlength: 5
                    },
                    confirm: {
                        minlength: 5,
                        equalTo: "#Password",
                    },
                    question: "required",
                    answer: "required"
                },
                success: function () {
                    xval = true;
                },
                messages: {
                    UserN: "Please enter your last name",
                    pass: {
                        required: "Provide a password",
                        minlength: "Password length at least 5 characters!"
                    },
                    confirm: {
                        minlength: "Password length at least 5 characters!",
                        equalTo: "Enter the same password as above"
                    },
                    question: "Please enter a security question",
                    answer: "Please enter answer to security question"
                }
            });

            if (jQuery("#Merchant_Registration").valid()) {
                return true;
            }

这是我的标记代码:

<p>
                <label>Username:</label>
                <span class="field">
                <asp:TextBox ID="UserName" class="required" runat="server" name="UserN"></asp:TextBox>
                </span>
                </p>

                <p>
                <label>Password:</label>
                <span class="field">
                <asp:TextBox ID="Password" class="required" runat="server" name="pass"></asp:TextBox>
                </span>
                </p>

                <p>
                <label>Re-type Password:</label>
                <span class="field">
                <asp:TextBox ID="Password2" class="required" runat="server" name="confirm"></asp:TextBox>
                </span>
                </p>

                <p>
                <label>Security Question:</label>
                <span class="field">
                <asp:TextBox ID="SecurityQ" class="required" runat="server" name="question"></asp:TextBox>
                </span>
                </p>

                <p>
                <label>Security Answer:</label>
                <span class="field">
                <asp:TextBox ID="SecurityA" class="required" runat="server" name="answer"></asp:TextBox>
                </span>
                </p>

在我的密码字段中,它不检查用户输入是否相同......并且不显示消息..

而其他文本框,当点击下一个按钮时,显示的错误是“此字段是必需的”而不是预先设置的消息......

有人可以帮助我......谢谢你。

1 个答案:

答案 0 :(得分:0)

您需要使用name属性作为验证程序

例如:

<form id="Merchant_Registration">
    <p>
        <label>Username:</label>
        <span class="field">
            <input ID="UserName" name="UserN"/>
        </span>
    </p>

    <p>
        <label>Password:</label>
        <span class="field">
            <input ID="Password" name="Password"/>
        </span>
    </p>

    <p>
        <label>Re-type Password:</label>
        <span class="field">
            <input ID="Password2" name="Password2"/>
        </span>
    </p>

    <p>
        <label>Security Question:</label>
        <span class="field">
            <input ID="SecurityQ" name="SecurityQ"/>
        </span>
    </p>

    <p>
        <label>Security Answer:</label>
        <span class="field">
            <input ID="SecurityA" name="SecurityA"/>
        </span>
    </p>
</form>

演示:Fiddle