Using regex to validate passwords | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Using regex to validate passwords

I was trying to validate the strength of passwords in this way using regex at least: one number, one special character, at one Capital Letter, and 8 characters long. I thought these would do: re.compile(r'[a-zA-Z0-9+-!._]{8,}') re.compile(r'(_\.\+\-!\?)+[a-z]+[A-Z]+[0-9]+') However, both aren't working: the first one doesn't calculate the 'at least' rule, while the second only matches in a specific order, which is useless. How can we do that? Your answer would clarify much about practical use of regular expressions.

20th Jan 2022, 2:14 PM
Hojiakbar
Hojiakbar - avatar
1 Answer
+ 3
one number, one special character, at one Capital Letter, and 8 characters long. ((?=.*\d)(?=.*\W)(?=.*[A-Z]).{8,}) you can check your regex at https://regex101.com/ to learn regex is here https://regexr.com/
23rd Jan 2022, 11:13 PM
Smith Welder
Smith Welder - avatar