JS检查密码强度 检查密码复杂度

清华大佬耗费三个月吐血整理的几百G的资源,免费分享!....>>>

$('#pass').keyup(function (e)
{
    var strongRegex = new RegExp("^(?=.{8,})(?=.*[A-Z])(?=.*[a-z])(?=.*[0-9])(?=.*\W).*$", "g");
    var mediumRegex = new RegExp("^(?=.{7,})(((?=.*[A-Z])(?=.*[a-z]))|((?=.*[A-Z])(?=.*[0-9]))|((?=.*[a-z])(?=.*[0-9]))).*$", "g");
    var enoughRegex = new RegExp("(?=.{6,}).*", "g");
    if (false == enoughRegex.test($(this).val()))
    {
        $('#passstrength').html('More Characters');
    }
    else if (strongRegex.test($(this).val()))
    {
        $('#passstrength').className = 'ok';
        $('#passstrength').html('强!');
    }
    else if (mediumRegex.test($(this).val()))
    {
        $('#passstrength').className = 'alert';
        $('#passstrength').html('中!');
    }
    else
    {
        $('#passstrength').className = 'error';
        $('#passstrength').html('弱!');
    }
    return true;
}
);