我试图将以下规则放在正则表达式中,以便在我的javascript代码中使用,但是没有运气,
这是规则:至少2个字符,包括特殊字符,2位数字,并且最小长度为8
我的正则表达式
/^(?=(?:[^A-Za-z]*[A-Za-z]){2})(?=(?:\D*\d){2})[A-Za-z0-9]{8,}$/
答案 0 :(得分:0)
var regexTests = {
"Needs at least 2 letters or special characters": /(.*[A-Z!@#$%^&*()_+\-=[\]{}|;:<>?,./]){2,}/i,
"Needs at least 2 digits": /(.*\d){2,}/,
"Needs at least 8 total characters": /.{8,}/
};
function testText(txt) {
return Object.keys(regexTests).filter(function(error) {
return !regexTests[error].test(txt);
});
}
console.log(testText("12"));
console.log(testText("gg"));
console.log(testText("g1"));
console.log(testText("g11f"));
console.log(testText("23df78sd"));