respect-validation/docs/MinimumAge.md
Henrique Moody 8d44bc3407
Refactor rules related to age
The "Age" rule was removed because it had too many responsibilities.
Instead "MaximumAge" was created (since there is already "MinimumAge").

This commit also introduces "AbstractAge" rule that is been used in both
mentioned rules.
2018-02-24 09:28:54 +01:00

1 KiB

MinimumAge

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

Validates a minimum 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::minimumAge(18)->validate('18 years ago'); // true
v::minimumAge(18, 'Y-m-d')->validate('1987-01-01'); // true

v::minimumAge(18)->validate('17 years ago'); // false
v::minimumAge(18, 'Y-m-d')->validate('2010-09-07'); // false

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

Changelog

Version Description
0.3.9 Created

See also: