1

我正在尝试为项目自定义密码强度计,但我不断收到 Javascript/jQuery 中的 RegEx 语法无效的量词错误。我试过转义反斜杠,消除正斜杠,在堆栈和谷歌上搜索。我找到了一些关于此的信息,但他们的解决方案似乎对我没有帮助。我希望有人可以在下面的函数代码中发现它。您的帮助将不胜感激。

$('#rPassword').keyup(function() {
    return passwordChanged();
});

function passwordChanged()
{
    var pwd = $('#rPassword').val();
    var noofchar=/^.*(?=.{3,}).*$/;
    var checkspace=/\s/;    
    var best = /(?=^.{8,}$)(?=.*\d)(?=.*\W+)(?![.\n])(?=.*[A-Z])(?=.*[a-z]).*$/; // 8 character minimum, upper-case letter, Lower-case letter, digit, special character
    var strong = /(?=^.{8,}$)((?=.*\d)|(?=.*\W+))(?![.\n])(?=.*[A-Z])(?=.*[a-z]).*$/; // 8 character minimum, upper-case letter, lower-case letter, digit or special character. Examples: “15NotEasy”,”Bett.er-Yet”
    var weak = /(?=^.{6,}$)(?=.*\d)(?=.*[A-Za-z]).*$/; // 6 character minimum, upper-case letter or lower-case letter, digit. Examples: “common1″,”7etmein”
    var bad = /[a-zA-Z0-9\_\-]{3,}$/; // 3 characters or longer, digits, upper or lower case letters. Examples: “easy”,”8892″,”NOTSECURE”

    if (true==checkspace.test(pwd)) {
        $('#rPasswordStrength').animate({
            width: '0%',
            backgroundColor: '#eb001f'
        }, 500)
    } else if (false==noofchar.test(pwd)) {
        $('#rPasswordStrength').animate({
            width: '0%',
            backgroundColor: '#eb001f'
        }, 500);
    } else if(best.test(pwd)) {
    $('#rPasswordStrength').animate({
        width: '100%',
        backgroundColor: '#1ca456'
    }, 500);          
    } else if(strong.test(pwd)) {
        $('#rPasswordStrength').animate({
            width: '75%',
            backgroundColor: '#8eda2a'
        }, 500);              
    } else if(weak.test(pwd)==true && bad.test(pwd)==true) { 
        $('#rPasswordStrength').animate({
            width: '50%',
            backgroundColor: '#ff7e0b'
        }, 500);              
    } else if(bad.test(pwd)) {
        $('#rPasswordStrength').animate({
            width: '25%',
            backgroundColor: '#eb001f'
        }, 500);              
    }
}
4

0 回答 0