Having some problem with FormControl() Validators.pattern() with this regex expression for validate password with 1 char, 1 digit, min 8 chars, max 16 chars.
Tested passwords that pass the validators:
asdfqwer //that should not pass the validator
zxcvasdf //that should not pass the validator
asdfqwer2 //that's correct
Tested password that do not pass the validators:
programm //that's correct
Trying this pattern in server-side or using online regex test platforms there are no problems
// some code
password: new FormControl('',
[
Validators.minLength(8),
Validators.maxLength(16),
Validators.pattern('^$|^(?=.*[A-Za-z])(?=.*\d)[A-Za-z\d]{8,16}$')
]),
// some code
^$at start ?^(?=.*[A-Za-z])(?=.*\d)[A-Za-z\d]{8,16}$this is enough you don't need to check length also