longerThan
Validate that a string is strictly longer than another field's string.
Signature
NguardValidators.String.longerThan(fieldKey: string): ValidatorFn
| Parameter | Type | Description |
|---|---|---|
fieldKey | string | The 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({
password: new FormControl(''),
fullPassword: new FormControl('', [
NguardValidators.String.longerThan('password'),
]),
});
Template-driven forms
<input ngModel name="password" />
<input ngModel name="fullPassword" [nguardLongerThan]="'password'" />
Error key
{ longerThan: true }
Notes
- The check is strict (
>). Equal lengths fail. - Both fields must be strings — non-string siblings cause failure.
- If the control has no parent form group, the validator fails.
See also
longerOrEqualTo— inclusive variantshorterThan— opposite directionminLength— same operator but compares to a literal length