respect-validation/docs/rules/MaxAge.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

1.1 KiB

MaxAge

  • MaxAge(int $age)
  • MaxAge(int $age, string $format)

Validates a maximum age for a given date. The $format argument should be in accordance to PHP's date() function. When $format is not given this rule accepts Supported Date and Time Formats by PHP (see strtotime()).

v::maxAge(12)->validate('12 years ago'); // true
v::maxAge(12, 'Y-m-d')->validate('2013-07-31'); // true

v::maxAge(12)->validate('13 years ago'); // false
v::maxAge(18, 'Y-m-d')->validate('1988-09-09'); // false

Using Date before is a best-practice. This rule does not accepts instances of DateTimeInterface.

Categorization

  • Date and Time

Changelog

Version Description
2.0.0 Created based on removed Age rule

See also: