equalTo<T> function

ValidatorFn<T> equalTo<T>(
  1. FormControl<T> other, {
  2. String? message,
})

Returns a validator that checks this control's value equals other's value. Useful for "confirm password" fields.

The comparison runs every time the current control is validated. To also re-validate when other changes, call other.addListener(() => thisControl.validate()).

Implementation

ValidatorFn<T> equalTo<T>(FormControl<T> other, {String? message}) {
  return (value) {
    if (value != other.value) {
      return message ?? 'values must match';
    }
    return null;
  };
}