feat: add password match validator for password and retype fields

This commit is contained in:
Polianin Nikita 2024-06-11 00:26:00 +03:00
parent b0b41fcdc5
commit 6fd78e7830

View File

@ -0,0 +1,17 @@
import {AbstractControl, ValidationErrors, ValidatorFn} from '@angular/forms';
export function passwordMatchValidator(password: string, retypePassword: string): ValidatorFn {
return (control: AbstractControl): ValidationErrors | null => {
const passwordValue = control.get(password)?.value;
const retypePasswordControl = control.get(retypePassword);
if (retypePasswordControl?.value === passwordValue) {
retypePasswordControl!.setErrors(null);
return null;
} else {
const error = {passwordsMismatch: true};
retypePasswordControl!.setErrors(error);
return error;
}
};
}