respect-validation/docs/comparable-values.md
Henrique Moody b815fdff92
Move documentation about "Comparable Values"
This documentation is in the "rules" directory, but it should be outside
that directory since the "rules" directory is supposed to only have
documentation about rules.

Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2019-05-11 17:34:42 +02:00

30 lines
No EOL
912 B
Markdown

# Comparable values
For certain types you can't make comparisons out of the box in PHP but
Validation brings support to a few of them.
You can make comparison with the following data types:
- Countable: any object that implements `Countable` interface
- DateTimeInterface
- Numeric types
- Single character string
- Primitive types in general: normal operation comparison made by PHP
- Time string: [date and time format](http://php.net/datetime.formats)
that can be parsed by PHP
Below you can see some examples:
```php
v::min(100)->validate($collection); // true if it has at least 100 items
v::dateTime()
->between(new DateTime('yesterday'), new DateTime('tomorrow'))
->validate(new DateTime('now')); // true
v::numericVal()->max(10)->validate(5); // true
v::stringVal()->between('a', 'f')->validate('d'); // true
v::dateTime()->between('yesterday', 'tomorrow')->validate('now'); // true
```