简体   繁体   English

密码验证不起作用

[英]Password validation not working

https://secure.www.cartier.cn/zh-cn/服务/my-cartier/RegistrationStep1.html I am using below RegEx to validate my password using jQuery validation. https://secure.www.cartier.cn/zh-cn/服务/my-cartier/RegistrationStep1.html我正在使用下面的RegEx来使用jQuery验证来验证我的密码。

$.validator.addMethod("passwordTest", function(value, element) {
            return this.optional(element) || /^(?=.*\d)[0-9a-zA-Z\!\@\#\$\%\^\&\*\)\(\+\=\.\_\-\?\}\{\]\[\>\<\"\\\/\'\:\;]{8,}$/i.test(value);
        }, _objPropertiesMsg.passWeak);

Rules applied on password validation as mentioned in CARE-8804: 适用于密码验证的规则,如CARE-8804中所述:

min 8 alphanumerical chars
combination of letters & numbers
no consecutive repeat of a char more than 2 times

It is working till 8 characters but above 8 characters all validations fails. 它可以工作到8个字符,但超过8个字符时,所有验证都会失败。 Also it fails for 2 consecutive char check and accepting 8 only numbers. 同样,它连续2次进行字符检查失败,并且仅接受8个数字。

I guess it is generally not a good idea, to try to check all your conditions in just one regex. 我想尝试在一个正则表达式中检查所有条件通常不是一个好主意。

Instead, just check for length with pure javascript, have a regex checking for characters not occurring more than twice in a row and another one making sure that there is at least one digit followed by a non-digit or the other way around: 相反,只需使用纯JavaScript来检查长度,让正则表达式检查连续出现的字符不超过两次,另一个则要确保至少有一个数字后跟一个非数字或其他数字:

$.validator.addMethod("passwordTest", function(value, element) {
            return this.optional(element) || value.length>=8 && /^((.)\2?(?!\2))+$/i.test(value) && /(\d[^\d]|[^\d]\d)/.test(value);
        }, _objPropertiesMsg.passWeak);

Have a loom at a proof of concept at https://jsfiddle.net/jvL151ya/ 可以在https://jsfiddle.net/jvL151ya/上查看概念验证的织机

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM