Skip to content

Latest commit

 

History

History
45 lines (31 loc) · 1.06 KB

UndefOr.md

File metadata and controls

45 lines (31 loc) · 1.06 KB

UndefOr

  • UndefOr(Validatable $rule)

Validates if the given input is undefined or not.

By undefined we consider null or an empty string (''), which implies that the input is not set. This is particularly useful when validating form fields

v::undefOr(v::alpha())->validate(''); // true
v::undefOr(v::digit())->validate(null); // true

v::undefOr(v::alpha())->validate('username'); // true
v::undefOr(v::alpha())->validate('has1number'); // false

Note

For convenience, you can use the undefOr as a prefix to any rule:

v::undefOrEmail()->validate('not an email'); // false
v::undefOrBetween(1, 3)->validate(2); // true

Categorization

  • Nesting

Changelog

Version Description
3.0.0 Renamed from "Optional" to "UndefOr"
1.0.0 Created

See also: