Reputation: 299
I'm trying to create a RegExpression to meet the criteria below;
So far I got this;
^(?=.{8,})(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.\s).*$
However I can not get it to work. Any help would be greatly appreciated. I was never good at puzzles :)
Upvotes: 5
Views: 3396
Reputation: 336378
You're nearly there; it's just the .*
at the end that ignores your "no spaces/special characters" rules, and the (?=.\s)
lookahead is wrong (you probably meant (?!.*\s)
or (?=\S*$)
).
But you don't need that lookahead anyway because you can simply specify which characters are allowed (and enforce the "8 characters minimum" rule there, too):
^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)[A-Za-z\d]{8,}$
But why do you want to keep users from using non-alphanumeric characters in their passwords?
Upvotes: 6