Improve password validator to include more special characters

This commit is contained in:
faris Aljohari
2024-07-24 12:14:15 +03:00
parent aafb9e4da9
commit 0bdee7c2ea

View File

@ -11,12 +11,12 @@ export class IsPasswordStrongConstraint
{ {
validate(password: string) { validate(password: string) {
const regex = const regex =
/^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&])[A-Za-z\d@$!%*?&]{8,}$/; /^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[!"#$%&'()*+,-./:;<=>?@[\]^_`{|}~])[A-Za-z\d!"#$%&'()*+,-./:;<=>?@[\]^_`{|}~]{8,}$/;
return regex.test(password); return regex.test(password);
} }
defaultMessage() { defaultMessage() {
return 'password must be at least 8 characters long and include at least one uppercase letter, one lowercase letter, one numeric digit, and one special character.'; return 'Password must be at least 8 characters long and include at least one uppercase letter, one lowercase letter, one numeric digit, and one special character from the set !"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~.';
} }
} }