Skip to main content
Version: 0.10.0

truthy

Validate that the value is truthy in the JavaScript sense — i.e. Boolean(value) evaluates to true.

Signature

NguardValidators.Boolean.truthy: ValidatorFn

Rejects every falsy value: false, 0, '', null, undefined, NaN. Accepts everything else.

Reactive forms

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

const form = new FormGroup({
confirmed: new FormControl(true, [NguardValidators.Boolean.truthy]),
});

Template-driven forms

<input ngModel name="confirmed" nguardTruthy />

Error key

{ truthy: true }

Notes

  • This is purely about JavaScript truthiness. Strings like 'false' and '0' are truthy because they are non-empty strings — if you need Laravel-style acceptance, use accepted.

See also

  • falsy — opposite check
  • accepted — Laravel-style acceptance set
  • boolean — strict boolean-like type check