1

バリデータの add メソッドに問題があります

(function($) {

    $.validator.passwordRating = function(password, username){
        if (!password || password.length < 8 ){
            alert(password);  (<--- problem)
            return rating(0, "too-short");
        }
    }
    $.validator.passwordRating.messages = {
        "similar-to-username": "Too similar to username",
        "too-short": "Too short",
        "very-weak": "Very weak",
        "weak": "Weak",
        "good": "Good",
        "strong": "Strong"
    }

$.validator.addMethod("password", function(value, element, usernameField) {
    // use untrimmed value
    var password = element.value,
    // get username for comparison, if specified
        username = $(typeof usernameField != "boolean" ? usernameField : []);

    var rating = $.validator.passwordRating(password, username.val());
    // update message for this field

    var meter = $(".password-meter", element.form);

    meter.find(".password-meter-bar").removeClass().addClass("password-meter-bar").addClass("password-meter-" + rating.messageKey);
    meter.find(".password-meter-message")
    .removeClass()
    .addClass("password-meter-message")
    .addClass("password-meter-message-" + rating.messageKey)
    .text($.validator.passwordRating.messages[rating.messageKey]);
    // display process bar instead of error message

    return rating.rate > 2;
}, "&nbsp;");
// manually add class rule, to make username param optional
$.validator.classRuleSettings.password = { password: true };

})(jQuery);

上記のスクリプトでは、パスワードの値を 0 に戻すと機能しません。1から8までOKです。

皆様のご声援をよろしくお願いいたします。

4

0 に答える 0