$.validator.addMethod("validpassword", function(value, element) {
return this.optional(element) ||
/^.*(?=.{8,})(?=.*[a-z])(?=.*[A-Z])(?=.*[\d])(?=.*[\W]).*$/i.test(value);
}, "The password must contain a minimum of one lower case character," +
" one upper case character, one digit and one special character..");
上述正则表达式不区分大写和小写。怎么了?
答案 0 :(得分:9)
删除i
标志。它使RegEx 不区分大小写。另外,将[\W]
扩展为[\W_]
。
/^.*(?=.{8,})(?=.*[a-z])(?=.*[A-Z])(?=.*[\d])(?=.*[\W]).*$/i.test(value);
// Remove this ^
// Ok:
/^.*(?=.{8,})(?=.*[a-z])(?=.*[A-Z])(?=.*[\d])(?=.*[\W_]).*$/.test(value);