Skip to main content

greaterThan

Validate that a numeric value is strictly greater than another field's numeric value.

Signature

NguardValidators.Number.greaterThan(fieldKey: string): ValidatorFn
ParameterTypeDescription
fieldKeystringThe key of the sibling field to compare against

Reactive forms

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

const range = new FormGroup({
floor: new FormControl(0),
ceiling: new FormControl(0, [
NguardValidators.Number.greaterThan('floor'),
]),
});

Template-driven forms

<input ngModel name="floor" type="number" />
<input ngModel name="ceiling" type="number" [nguardGreaterThan]="'floor'" />

Error key

{ greaterThan: true }

Notes

  • The check is strict (>). Equal values fail.
  • Both fields must be numeric — non-numeric inputs (including a non-numeric sibling) cause failure.
  • If the control has no parent form group, the validator fails.
  • Numeric strings are accepted on both sides.

See also