respect-validation/docs/07-comparable-values.md
Henrique Moody 2f12b6c8d8
Rename "Max" to "LessThanOrEqual"
Although the name is much longer, it's more explicit what it does. I
confess that after a while without using Validation, even I get confused
about that. Besides, I would like to create another rule with the same
name, but that will behave differently.

Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2024-02-27 21:12:13 +01:00

940 B

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 that can be parsed by PHP

Below you can see some examples:

v::greaterThanOrEqual(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()->lessThanOrEqual(10)->validate(5); // true

v::stringVal()->between('a', 'f')->validate('d'); // true

v::dateTime()->between('yesterday', 'tomorrow')->validate('now'); // true