mirror of
https://github.com/Respect/Validation.git
synced 2026-03-18 08:09:51 +01:00
Since we have NotOptional rule now, we must keep the same opposite behaviour between these two rules. This commit also improve and increase tests from Optional rule and updates the documentation. No tests was made for messages on MODE_DEFAULT because it's not possible for a while since we don't have such much granularity control, but after some fixes on Not rule, maybe we will be able to do that, that's why I kept the messages on OptionalException.
21 lines
426 B
Markdown
21 lines
426 B
Markdown
# Optional
|
|
|
|
- `v::optional(v $rule)`
|
|
|
|
Validates if the given input is optional or not. By _optional_ we consider `null`
|
|
or an empty string (`''`).
|
|
|
|
```php
|
|
v::optional(v::alpha())->validate(''); // true
|
|
v::optional(v::digit())->validate(null); // true
|
|
```
|
|
|
|
|
|
***
|
|
See also:
|
|
|
|
* [NoWhitespace](NoWhitespace.md)
|
|
* [NotBlank](NotBlank.md)
|
|
* [NotEmpty](NotEmpty.md)
|
|
* [NotOptional](NotOptional.md)
|
|
* [NullType](NullType.md)
|