Enhance password validation in registration component with improved regex pattern and increased max length

This commit is contained in:
Vincent Guillet
2025-11-26 09:30:59 +01:00
parent 7c82cf0d3f
commit 1efe158631

View File

@@ -56,6 +56,11 @@ export class RegisterComponent implements OnDestroy {
isSubmitted = false;
isLoading = false;
private readonly passwordPattern: RegExp = new RegExp(
'^(?=.*[a-z])(?=.*[A-Z])(?=.*\\d)(?=.*[\\p{P}\\p{S}]).{8,}$',
'u'
);
private readonly router: Router = inject(Router);
private readonly authService: AuthService = inject(AuthService);
@@ -90,14 +95,14 @@ export class RegisterComponent implements OnDestroy {
password: ['', [
Validators.required,
Validators.minLength(8),
Validators.maxLength(20),
Validators.pattern('^(?=.*[a-z])(?=.*[A-Z])(?=.*\\d)(?=.*[@$!%*?&])[A-Za-z\\d@$!%*?&]{8,}$')
Validators.maxLength(50),
Validators.pattern(this.passwordPattern)
]],
confirmPassword: ['', [
Validators.required,
Validators.minLength(8),
Validators.maxLength(20),
Validators.pattern('^(?=.*[a-z])(?=.*[A-Z])(?=.*\\d)(?=.*[@$!%*?&])[A-Za-z\\d@$!%*?&]{8,}$')
Validators.maxLength(50),
Validators.pattern(this.passwordPattern)
]],
termsAndConditions: [false, Validators.requiredTrue]
}, {validators: this.passwordMatchValidator});