Skip to main content

longerOrEqualTo

Validate that a string is at least as long as another field's string.

Signature

NguardValidators.String.longerOrEqualTo(fieldKey: string): ValidatorFn
ParameterTypeDescription
fieldKeystringThe key of the sibling field whose length is the target

Reactive forms

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

const form = new FormGroup({
minPassword: new FormControl(''),
password: new FormControl('', [
NguardValidators.String.longerOrEqualTo('minPassword'),
]),
});

Template-driven forms

<input ngModel name="minPassword" />
<input ngModel name="password" [nguardLongerOrEqualTo]="'minPassword'" />

Error key

{ longerOrEqualTo: true }

Notes

  • The check is >= (inclusive). Equal lengths pass.
  • Both fields must be strings — non-string siblings cause failure.
  • If the control has no parent form group, the validator fails.

See also