简体   繁体   English

jQuery密码强度检查器问题

[英]Jquery password strength checker issue

I have a jquery password live validation form HERE 我有一个jquery密码验证直播形式HERE

Example from Js Fiddle Js Fiddle的例子

This example guides to add proper password. 本示例指导添加正确的密码。 When all the requirements satisfied it turns into green and the guide Tool tip Hides which is very Good. 当满足所有要求时,它会变成绿色,并且“工具提示”隐藏指南非常好。 Thanks to j08691l for upto this. 感谢j08691l的帮助。

But I am facing one issue like after satisfying the conditions when the tool tip popup hides it's not came back when I use backspace and want to remove. 但是我遇到了一个问题,例如在满足条件时,当工具提示弹出窗口隐藏起来时,当我使用退格键并要删除时,它不会再出现。

So is this possible If I use backspace after hiding the tool tip Pop and it's again show up with all the conditions in Red color which are removed and with Green Color which are not removed? 如果我在隐藏工具提示“弹出”之后使用退格键,并且该条件再次以所有已删除的红色和未删除的绿色显示,那么是否有可能?

JS: JS:

$(document).ready(function () {
    $('input[type=password]').keyup(function () {
        // set password variable
        var pswd = $(this).val();
        if (pswd.length < 8) {
            $('#length').removeClass('valid').addClass('invalid');
        } else {
            $('#length').removeClass('invalid').addClass('valid');
        }
        //validate letter
        if (pswd.match(/[A-z]/)) {
            $('#letter').removeClass('invalid').addClass('valid');
        } else {
            $('#letter').removeClass('valid').addClass('invalid');
        }
        //validate capital letter
        if (pswd.match(/[A-Z]/)) {
            $('#capital').removeClass('invalid').addClass('valid');
        } else {
            $('#capital').removeClass('valid').addClass('invalid');
        }

        //validate number
        if (pswd.match(/\d/)) {
            $('#number').removeClass('invalid').addClass('valid');
        } else {
            $('#number').removeClass('valid').addClass('invalid');
        }

        if ($('#pswd_info li.valid').length == 4) $('#pswd_info').fadeOut();
    });
    $('input[type=password]').focus(function () {
        // focus code here
    });
    $('input[type=password]').blur(function () {
        // blur code here
    });

    $('input[type=password]').keyup(function () {

        // keyup code here
    }).focus(function () {
        $('#pswd_info').show();
    }).blur(function () {
        $('#pswd_info').hide();
    });


}); 

You need: 你需要:

    if ($('#pswd_info li.valid').length == 4) {
        $('#pswd_info').fadeOut();
    } else {
        $('#pswd_info').fadeIn();
    }

You're never fading the info in if the validation criteria are not met. 如果您不满足验证条件,则永远不会褪色信息。

Actually, I suggest inverting the condition, so you don't need to hard-code the number of conditions: 实际上,我建议反转条件,因此您无需对条件数进行硬编码:

    if ($('#pswd_info li.invalid').length == 0) {
        $('#pswd_info').fadeOut();
    } else {
        $('#pswd_info').fadeIn();
    }

DEMO DEMO

您可以只使用输入标签内的range属性,例如And,您可以节省大量时间和额外的编码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM