Skip to content

Instantly share code, notes, and snippets.

@narainsagar
Created November 15, 2016 13:12
Show Gist options
  • Save narainsagar/53dd61c767bf65db800bf388cf24d3ff to your computer and use it in GitHub Desktop.
Save narainsagar/53dd61c767bf65db800bf388cf24d3ff to your computer and use it in GitHub Desktop.
solution for the password/confirm password matching.

solution for the password/confirm password matching:

matchingPasswords(passwordKey: string, passwordConfirmationKey: string) {
    return (group: FormGroup) => {
      let passwordInput = group.controls[passwordKey];
      let passwordConfirmationInput = group.controls[passwordConfirmationKey];
      if (passwordInput.value !== passwordConfirmationInput.value) {
        return passwordConfirmationInput.setErrors({passwordMismatch: true});
      }
    };
}

this.formBuilder.group({
      ...
      password: [this.initialUserDetail.password],
      confirmPassword: [this.initialUserDetail.confirmPassword],
      ...
    }, { validator: this.matchingPasswords('password', 'confirmPassword') });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment