0

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
    }
chan
  • 274
  • 1
  • 5
  • 24
  • 1
    Why the specific requirement of at least 3 lowercase characters? You're complicating it for both you as developer and the user who will have to pick a password matching your very specific rules. Refer to [this answer](http://stackoverflow.com/a/21456918/1276128), where you can find very similar regex (at least 1 lowercase, uppercase, digit special character and length of 8+). Also some simplifications, you don't need to check for empty as this regex will fail in that case, and you can just use `return regex.text(password)`. – Marko Gresak Apr 30 '16 at 02:13
  • @marko.. thanks...that helped me – chan Apr 30 '16 at 02:21

1 Answers1

1
/^(?=.*?[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

StoledInk
  • 164
  • 2
  • 15