Skip to main content

confirmed

Validate that the field equals a sibling field (typically used for "confirm password" patterns).

Signature

NguardValidators.CrossField.confirmed(fieldKey: string): ValidatorFn
ParameterTypeDescription
fieldKeystringThe key of the sibling field whose value the current field must match

Reactive forms

import { FormControl, FormGroup } from '@angular/forms';
import { NguardValidators } from 'ng-nguard';

const form = new FormGroup({
password: new FormControl(''),
passwordConfirm: new FormControl('', [
NguardValidators.CrossField.confirmed('password'),
]),
});

Template-driven forms

<input ngModel name="password" type="password" />
<input ngModel name="passwordConfirm" type="password" [nguardConfirmed]="'password'" />

Error key

{ confirmed: true }

Notes

  • The check is strict (===); type coercion is not applied. '1' and 1 are not considered equal.
  • If the control has no parent form group, the validator fails (the sibling can't be looked up).
  • If the sibling field is null or undefined, the validator fails — even if the current field is also empty. Use Validators.required separately if you want to allow both fields empty.
  • Empty strings on both sides are considered equal and pass validation.

See also

  • same — same equality logic but configurable strict/loose mode
  • different — opposite check