The requirements I've been set are...
MUST match (1 minimum character/number):
- 1 number
(?=.*\d)
- 1 lower case character
(?=.*[a-z])
- 1 upper case character
(?=.*[A-Z])
- no whitespace
(?!.*\s)
- Between 8 and 40 characters
.{8,40}
CAN match, but doesn't have to:
- Special characters limited to
$*%!.,^
This is what I have so far: /(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?!.*\s).{8,40}/
I'd like to keep it segmented out the way I do for readability - Unless there's a reason not to?! Happy to change if there are any performance benefits, or if I've done something silly/pointless?
The above works for the most part, including my special characters. However, when I type in a "restricted" character, such as @
, it still matches.
I'm a bit lost, so any help would be very much appreciated! Thank you!
Examples of what SHOULD match:
- abcABC123
- aaBB33!!
- !a*Bc9!.abBC*4
Examples of what SHOULD NOT match:
- abc ABC 123
- abc@ABC?123
- áááBBB333
Restrictions:
Anything that is NOT a-z A-Z 0-9 or $*%!.,^
is considered a restricted character