1 / 3
May 2022

I want to create a validator for the correctness of the entered password, which should contain an uppercase letter, a lowercase letter, a number and a special character. I wanted to do this through a regular expression, but I have trouble creating the correct pattern. Can you help and point out what’s wrong with this code?

print (‘Create a password, which include: uppercase, lowercase, digits and special characters.’)
password = input()
pattern = re.compile (r’ [a-z] & [A-Z] & [0-9] & [!@#$%^&*]’)
validation = pattern.search(password)
if validation:
print (‘Your password is corect’)
else:
print(‘Your password is uncorect’)

  • created

    May '22
  • last reply

    May '22
  • 2

    replies

  • 521

    views

  • 2

    users

  • 1

    link

Something like this:

(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&])[A-Za-z\d@$!%*?&]

Found here5.