密码强度JQuery

时间:2013-09-30 08:44:46

标签: javascript jquery

我需要一些帮助。我是JS和Jquery的新手,遇到了以下问题:我有3个密码字段:当前通行证,新通行证和确认通行证。密码计检查所有3个字段,但我只需要新的传递字段。

这是代码

$.validator.passwordRating.messages = {
        "similar-to-username": "similara cu emailul",
        "too-short": "prea scurta",
        "very-weak": "prea slaba",
        "weak": "slaba",
        "good": "buna",
        "strong": "excelenta"
    };

    $.validator.messages = {
        "email": "Scrie o adresa de email valida.",
        "password": "",
        "password_confirm": "",
        "required": "Acest camp este obligatoriu.",
    };

    var validator = $("#pass_form").validate({
        rules: {
            password: {
                password: "#password1"
            },
            password_confirm: {
                required: true,
                equalTo: "#password2"
            }
        },
        messages: {
            password_confirm: {
                required: "Repeta parola",
                minlength: jQuery.format("Parola trebuie sa fie de cel putin {0} caractere"),
                equalTo: "Scrie aceeasi parola"
            }
        }
    }); 

    $("#password").valid(); 

<form action="" method="post" id="pass_form">
                        <div class="element left">
                            <label for="password"><Bla/></label>
                            <input type="password" name="password" id="password" placeholder="Password">
                                    <label class="error"></label>

                        </div>
                        <div class="element left double">
                            <div class="left spacer">
                                <label for="password1"></label>
                                <input type="password" id="password1" name="password1" placeholder="New Pass">

                                    <label class="error"></label>

                            </div>
                            <div class="left spacer" id='password_div'>
                                <label for="password2"><fmt:message key="profile.profile_data.parola_noua2"/></label>
                                <input type="password" id="password2" name="password2" oninput="compare()"/>
                                <label class="error" id='compare_error'></label>

                                    <label class="error">/></label>

                                <input type="hidden" name="password1hid" id="password1hid" value=""/>
                            </div>
                            <div class="left strength">
                                <div class="password-meter">
                                    <div class="password-meter-message">&nbsp;</div>
                                    <div class="password-meter-bg">
                                        <div class="password-meter-bar"></div>
                                    </div>
                                </div>

                            </div>
                        </div>
                        <div class="element left">
                            <button onclick="document.getElementById('pass_form').submit()" name="password"></button>
                            <input type="hidden" name="field" id="field" value="pass" />

                        </div>                            
                    </form>

1 个答案:

答案 0 :(得分:1)

var validator = $("#pass_form").validate({
        rules: {

//Enter the id of new password.. i have used password1
password1: {
                //Conditions
            },
//Enter the id of confirm new password.. i have used password2
            password2: {
                  //Conditions
            }
        },
        messages: {
            password2: {
                required: "Repeta parola",
                minlength: jQuery.format("Parola trebuie sa fie de cel putin {0} caractere"),
                equalTo: "Scrie aceeasi parola"
            }
        }
    }); 

希望这有帮助