Skip to main content
Version: 0.6.0

boolean

Validate that the value is boolean-like (Laravel parity). Accepts the same six inputs as Laravel's boolean rule.

Signature

NguardValidators.Boolean.boolean: ValidatorFn
Accepted inputNotes
true, falsenative booleans
1, 0numeric truth/false
'1', '0'stringified numeric truth/false

Anything else — including 'true', 'false', 'yes', null, undefined — fails.

Reactive forms

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

const form = new FormGroup({
isActive: new FormControl(false, [NguardValidators.Boolean.boolean]),
});

Template-driven forms

<input ngModel name="isActive" nguardBoolean />

Error key

{ boolean: true }

Notes

  • This is a type/shape check — for "value evaluates as truthy" use truthy; for accepting strings like 'yes' and 'on' use accepted.
  • null and undefined are rejected. Pair with another rule (e.g. an explicit nullable check) if you want to allow them.

See also

  • accepted — Laravel-style acceptance set
  • declined — Laravel-style decline set
  • truthy — any truthy value
  • falsy — any falsy value