I'm trying to validate a password with the following regex:
^(?=.*[A-Z])(?=.*[a-z])(?=.*[0-9])(?=.{8,})
.
Note that there is no terminating $
char, because that would prevent valid passwords from being accepted. (I'm not sure why the input field doesn't terminate the string).
However, Angular's Validators.pattern
adds the end of string char. And therefore my valid passwords fail.
How do I prevent the pattern validator from adding the $
?
I suppose I could roll my own password validator, but surely there is a better solution...?
EDIT: Passwords that should succeed:
- Test1234
- tEst1234
- tesT1234
- 1234Test
- 1234tesT
- t#St1234
Passwords that should fail:
- TEST1234
- test1234
- tEst123
- Test123
- testtest
- 12345678
Validator declaration:
this.password = new FormControl('', [Validators.required, Validators.pattern('^(?=.*[A-Z])(?=.*[a-z])(?=.*[0-9])(?=.{8,})')]);
this.userForm.addControl('Password', this.password);