I've a reactive forms validation for a password, and the pattern is the following:
new RegExp('^(?=.*\\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[#$^+=!*()@%&]).{8,50}$');
My goal is to validate the string so it is:
- Between 8 & 50 characters
- Has a lower case letter
- Has an upper case letter
- Has a number
- And has a symbol
For some reason, it works like a charm, but if I enter a password that starts with a single number, the validation fails.
What am I doing wrong? Example passwords:
1dD5a971# -- doesn't match
11dD5a971# -- does match
The angular code:
static PASSWORD_PATTERN = new RegExp('^(?=.*\\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[#$^+=!*()@%&]).{8,50}$');
this.form= fb.group({
user: [...],
password: ['', [Validators.compose([
Validators.required,
Validators.min(8),
Validators.max(50),
Validators.pattern(AddUserComponent.PASSWORD_PATTERN)
])]]
};
Thank you in advance.