我正在尝试为项目自定义密码强度计,但我在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);
}
}