I'm having some trouble creating a regex for a password. It has the following requirements :
- at least 10 characters
- at least 1 uppercase letter
- at least 1 lowercase letter
- at least 1 special character
I currently created this line : `
"^(?=(.*[A-Z]) )(?=(.*[a-z]) )(?=(.*[0-9]) )(?=(.*[!@#$%^&*()_ =.]) ){10,}$"
` For a password like : Lollypop56@ it still gives me false.
CodePudding user response:
You forgot a full point after the lookahead of special characters. So it would be:
"^(?=(.*[A-Z]) )(?=(.*[a-z]) )(?=(.*[0-9]) )(?=(.*[!@#$%^&*()_ =.]) ).{10,}$"
CodePudding user response:
The regex should be
"^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*#?&])[A-Za-z\d@$!#%*?&]{10,}$"
I tested it on your example
Lollypop56@
and it returns true