respect-validation/docs/rules/MinAge.md

44 lines
1 KiB
Markdown
Raw Permalink Normal View History

# MinAge
2015-01-30 09:40:06 +01:00
- `MinAge(int $age)`
- `MinAge(int $age, string $format)`
2015-01-30 09:40:06 +01:00
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()][]).
2015-01-30 09:40:06 +01:00
```php
v::minAge(18)->validate('18 years ago'); // true
v::minAge(18, 'Y-m-d')->validate('1987-01-01'); // true
2015-01-30 09:40:06 +01:00
v::minAge(18)->validate('17 years ago'); // false
v::minAge(18, 'Y-m-d')->validate('2010-09-07'); // false
```
2015-01-30 09:40:06 +01:00
Using [Date](Date.md) before is a best-practice.
This rule does not accepts instances of [DateTimeInterface][].
2015-01-30 09:40:06 +01:00
## Categorization
- Date and Time
## Changelog
Version | Description
--------|-------------
0.3.9 | Created
***
2015-01-30 09:40:06 +01:00
See also:
- [Date](Date.md)
2018-12-11 13:31:50 +01:00
- [DateTime](DateTime.md)
- [Max](Max.md)
- [MaxAge](MaxAge.md)
- [Min](Min.md)
[date()]: http://php.net/date
[DateTimeInterface]: http://php.net/DateTimeInterface
[strtotime()]: http://php.net/strtotime
[Supported Date and Time Formats]: http://php.net/datetime.formats