简体   繁体   中英

Regex expression not working for password validation

I am trying to develop a regex pattern for password with following conditions 1) atleast 1 Uppercase character 2) atleast 3 lower case characters 3) atleast 1 digit 4) atleast 1 Special character 5) Minimum length should be 8 characters. This is my javascript function. Can somebody help me with the expression. Thanks

validatePassword : function(password){
        if(this.isEmpty(password))
        {
            return false;
        }
        var regex = /^(?=.*[A-Z])(?=.*[!@#$&*])(?=.*[0-9])(?=.*[a-z].*[a-z].*[a-z]).{8}$/;
        if(!regex.test(password))
        {
            return false
        }
        return true
    }
/^(?=.*?[A-Z])(?=(?:.*[a-z]){3})(?=.*?[0-9])(?=.*?[^\w\s]).{8,}$/

This regex will enforce these rules:

• At least one upper case
• At least three lower case
• At least one digit
• At least one special character
• Minimum 8 in length

JSFIDDLE

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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