I want to validate password entered by user for following criteria :
Password should be at least 8 characters long and should contain one number,one character an
I took a stab at this with Angular's built-in pattern validator and was able to come up with the following that checks for:
Numbers Special characters
password: [ '', [
Validators.required,
Validators.pattern('(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])(?=.*[$@$!%*?&])[A-Za-z\d$@$!%*?&].{8,}') ] ]
I'll add that I'm by no means a regex expert. This is simply what worked for me for a closely related case to the OP. Maybe it will help someone else. Mozilla's documentation helped a lot in figuring this out, specifically the Writing a regular expression pattern section.