0

one is password and the other one is account number, both of them have each input extra as confirm password and confirm account number. I have used reactive forms and is as follows:

TS:

private initAchForm() {
      this.achInfoForm = this.FB.group({
        password: ['',Validators.required],
        confirmpassword: ['',Validators.required],
        accountNumber: [null,Validators.required],
        reAccountNumber: [null,Validators.required],
      },
      { validator: ConfirmRoutingValidator.MatchPassword});
  }

have created one file which contains these custom things:

password match file;

import { AbstractControl } from '@angular/forms';
export class ConfirmPasswordValidator {
  static MatchPassword(control: AbstractControl) {
    let password = control.get('password').value;
    let confirmPassword = control.get('confirmPassword').value;
    if (password != confirmPassword) {
      control.get('confirmPassword').setErrors({ ConfirmPassword: true });
    }
    else {
      return null;
    }
  }
}

export class ConfirmAccountValidator {
  static MatchPassword(control: AbstractControl) {
    let password = control.get('accountNumber').value;
    let confirmPassword = control.get('reAccountNumber').value;
    if (password != confirmPassword) {
      control.get('reAccountNumber').setErrors({ ConfirmPassword: true });
    }
    else {
      return null;
    }
  }
}

I am trying to add 2 validators in one section, like { validator: ConfirmRoutingValidator.MatchPassword}, { validator: ConfirmAccountValidator.MatchPassword} but get an error as Expected 1-2 arguments, but got 3.

How can this be solved? I tried adding these values in the control names but it says value of undefined because it is not able to get those values.

1 Answer 1

1

Try to provide them in array, i.e.:

password: ['', [Validators.required, yourCustomValidator]]
Sign up to request clarification or add additional context in comments.

7 Comments

thanks for response i tried this as well but it throws error as value is undefined
ok, so maybe try to use Validators.compose() and put this array as it's parameter
reRoutingNumber: ['',Validators.compose([Validators.required,ConfirmRoutingValidator.MatchPassword])],
something like that?
@Bhrungarajni finally I've found why you're getting value of null error, your declaration has field named resetpassword, but in your validator you're using resetPassword with uppercase P and that's why it doesn't see this control value
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.