Comments (13)
Actually there is some legal complications on letting people below the legal age of the country signing for some services, but never heard of possible limitations for maximum age.
I do believe that if there are applications for that, than we should probably consider adding it or accept a pull request :)
@Petah Do you have some examples of use cases for that validator?
from validation.
@augustohp we have had problems with people submitting an age in the incorrect format, and/or with typos causing us to require implementing validation rules around it. Also when asking for a date of birth, expecting the user to be under 120 years should be an acceptable limitation.
I will look at implementing this based off the minimumAge validator and sending you a pull request.
from validation.
@Petah I think that could be a good idea to create two rules, if you can: lessThan
and greaterThan
, so minimumAge
and maximumAge
may extends these classes. What you thing?
Btw, you can just create the maximumAge
rule. Do what you think better. ;)
from validation.
We already have min
, max
and between
which are useful for validating ranges, and they work with dates as well. This works:
v::min('yesterday')->max('tomorrow')->validate(new DateTime('today'));
The minimumAge validator has a single difference from max
though: the validation message is more specific, it tells you about ages, not just generic dates.
Perhaps an age
validator would be something nice:
v::age('+18')->validate(...
v::age('-120')->validate(...
The string containing the sings + and - can be directly reused in a strtotime operation inside the validation implementation, we just need to append the "years" suffix:
strtotime("+18 years"); //It Works!
Thoughts?
from validation.
+0
Nothing, just agreed, btw I don't know if age is a good name...
from validation.
ageDifference?
from validation.
ageDiff ?
from validation.
No, I thinks age is better.
+1 for age
from validation.
My suggestion is to validate ages from a date of birth, something like this:
// $format should be a date format
v::Age($format[, $min=0[, $max=120]])
To validate numbers we can use the between validator.
from validation.
I'm not sure about the format. The same could be written like:
v::date($format)->age(18, 90);
I believe keeping them separate is more modular.
Anyway, your suggestion is by far the best. Removing the format parameter we can even make it backward-compatible with the minimumAge() validator and deprecate it.
+1 for v::age($min, $max)
from validation.
Nice, I've put format parameter because I was not sure that this kind of fluent validator was possible... so
+1 for v::age($min, $max)
from validation.
I've update the issue description to easy contributions and resume discussion until now.
from validation.
This rule is going to be available in 9.0
version.
from validation.
Related Issues (20)
- Translation from array HOT 3
- Respect\Stringifier\stringify() undefined function HOT 1
- Given a multirule validator, is there a usage pattern for testing a single rule? HOT 1
- ~~Why does v::containsAny(array('mod'))->validate('mode') return true?~~ Because the expected functionality is confused with In ( https://respect-validation.readthedocs.io/en/latest/rules/In/ ) HOT 1
- messages translate HOT 1
- define different error messages HOT 2
- Is there a roadmap or future plan for this repository? HOT 10
- filterVal not correct working with FILTER_VALIDATE_INT HOT 1
- CountryCode validation for Montenegro HOT 2
- IntVal: ctype_digit gives a deprecated notice in PHP 8.1 HOT 3
- ctype_digit deprecation notice HOT 1
- Release 2.2.4 HOT 2
- Roadmap to 2.3 HOT 13
- Code coverage in local environment HOT 2
- [documentaiton] Validation for a full array of data HOT 3
- Formatter inconsequently stringifies values HOT 6
- IBAN Validation with non-breaking spaces HOT 1
- How do custom validation rules throw custom error messages? HOT 2
- How to compare two field HOT 1
- DateTime validation fails on valid ISO-8601 timestamp HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from validation.