I have 4 form fields and i want to check whether the 'oldpass' and 'newpass' fields are same using reactive form.
this.changePasswordForm = fb.group({
'oldpass': ['', Validators.compose([Validators.required, Validators.minLength(6)])],
'newpass': ['', Validators.compose([Validators.required, Validators.minLength(6)])],
'confirmpass': ['', Validators.compose([Validators.required])],
'otp': ['']
},{validator: CustomValidator.matchConfirmFields('newpass', 'confirmpass')});
And i am able to validate the 'newpass' and 'confirmpass' fields using the following code.
static matchConfirmFields(pass: string, confirmpass: string) {
return (group: FormGroup): {[key: string]: any} => {
let spass = group.controls[pass];
let sconfirmpass = group.controls[confirmpass];
if (spass.value !== sconfirmpass.value) {
return {
mismatchedPasswords: true
};
}
}
}
How do i validate 'oldpass' and 'newpass' fields similar way.