feat: add password match validator for password and retype fields
This commit is contained in:
parent
b0b41fcdc5
commit
6fd78e7830
17
src/services/password-match.validator.ts
Normal file
17
src/services/password-match.validator.ts
Normal 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;
|
||||
}
|
||||
};
|
||||
}
|
Loading…
Reference in New Issue
Block a user