RegEx for password verification (1 lowercase, 1Uppercase, 1 digit, NoSpaces)

I am trying to create RegExpression to meet the following criteria:

  • at least 1 lower case
  • at least 1 uppercase
  • at least 1 digit
  • No spaces
  • 8 characters minimum
  • No special characters

So far, I got it;

^(?=.{8,})(?=.*[az])(?=.*[AZ])(?=.*\d)(?=.\s).*$ 

However, I cannot get it to work. Any help would be greatly appreciated. I never knew puzzles :)

+4
source share
1 answer

You're almost there; it's simple .* at the end, which ignores your โ€œno spaces / special charactersโ€ rules, and the look (?=.\s) wrong (you probably meant (?!.*\s) or (?=\S*$) )).

But you still don't need this lookahead, because you can simply specify which characters are allowed (and also apply the "8 characters minimum" rule):

 ^(?=.*[az])(?=.*[AZ])(?=.*\d)[A-Za-z\d]{8,}$ 

But why do you want users to not use alphanumeric characters in their passwords?

+5
source

Source: https://habr.com/ru/post/1438393/


All Articles