I am trying to include the following password rules via Validators.pattern in my angular 4 project using regex.
My external stakeholder would like a users password to be valid if it included a lowercase letter, uppercase letter and a Number OR Special character.
Below is the regex I am using, Pattern 1 works fine as does pattern2, however when I try to do the OR of them in pattern3 it does not work.
//passwordPattern1='^(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[0-9]).{8,}$';// must include numbers
//passwordPattern2='^(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[#?!@$%^&*-]).{8,}$';//must include special characters
passwordPattern3='^(((?=.*[a-z])(?=.*[A-Z])(?=.*[0-9]))|((?=.*[a-z])(?=.*[A-Z])(?=.*?[#?!@$%^&*-.])))';//Numbers or Special characters
Below is how I add it to my formGroup. see line 3
this.form = this.fb.group({
username: [null, Validators.compose([Validators.required, Validators.minLength(4), Validators.maxLength(20)])],
password: [null, Validators.compose([Validators.required,Validators.minLength(8), Validators.maxLength(128), Validators.pattern(this.passwordPattern3)])],
confirmPassword: [null, Validators.compose([Validators.required, Validators.minLength(8), Validators.maxLength(128)])]
}, {validator: matchingPasswords('password', 'confirmPassword')});
Does anyone know why the third password pattern does not seem to work in angular, and what I could do to make it work?
I tested the REGEX at http://rubular.com/ in passwordPattern3 and it works as desired. Anything I may be missing in Angulars validators.pattern()?
Regarding the security of these requirements- I am aware these rules are not the best approach for the security of a user. For this effort, I, unfortunately, do not have the influence to change the requirements from the external stakeholder. But I am awarewhy such rules may be ineffective