Skip to content
Advertisement

how to check if a string fullfil with multiple regex and capture that portion that match?

What I want

I’m working with a django form and it takes a password input. I need to pass the input value for multiple regexes, which will test if:

  • at least one character is a lowecase
  • at least one character is a uppercase
  • at least one character is a number
  • at least one character is a especial character (symbol)
  • 8 characters minimum

And I would like to know which of these conditions were fulfilled and which were not.

What I’ve done

JavaScript

Advertisement

Answer

While you can use a regex here, I would stick to normal Python:

JavaScript

Output:

JavaScript

This allows you to modify the password requirements in a more flexible fashion, and in case you ever want to say “you need X of this character class”…

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement