我使用过aspx格式的正则表达式验证器。我使用过这种((?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*\W).{6,15})
表达,效果很好。
我正在尝试在javascript中使用相同的表达式,但是为什么会失败呢?
使用javascript
var regularExpression = ((?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*\W).{6,15})
if (regularExpression.test(newPassword)) {
alert("Password must be at least 6 characters, not more than 15 characters, and must include at least one upper case letter, one lower case letter, one special character and one numeric digit.");
return false;
}
答案 0 :(得分:1)
对于RegExp,您应该使用/
而不是(
var regularExpression = /(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*\W).{6,15}/;
if (regularExpression.test(newPassword)) {
alert("Password must be at least 6 characters, not more than 15 characters, and must include at least one upper case letter, one lower case letter, one special character and one numeric digit.");
return false;
}