mirror of
https://github.com/Respect/Validation.git
synced 2024-06-08 00:32:16 +02:00
707dcae65f
This commit will rename the "Optional" rule to"UndefOr" while soft deprecating the old name. It should work the same as the previous one but with a different name. It will also prefix the result ID, allowing more message customization. While working on it, I realized that the prefix "undefOr" had a typo, and it was using "undefOf" instead. I fixed that, too. Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
1.1 KiB
1.1 KiB
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: