Create `age` validator (Deprecates `minimumAge`) #103

Closed
Petah opened this Issue Jan 13, 2013 · 13 comments

Comments

Projects
None yet
6 participants

Petah commented Jan 13, 2013

This resumes the discussion happened below until @caferrari comment:

  1. Create an age validation rule: v::age($min, $max=null).
  2. Deprecate (remove) mininumAge validation rule in favor of the age rule.

Original message (for historical purposes):

There is a minimumAge but no maximumAge.
Any reason, or just missed?

Owner

augustohp commented Jan 16, 2013

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?

Petah commented Jan 21, 2013

@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.

Owner

henriquemoody commented Jan 21, 2013

@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. ;)

Owner

alganet commented Jan 21, 2013

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?

Owner

henriquemoody commented Jan 21, 2013

+0
Nothing, just agreed, btw I don't know if age is a good name...

Owner

alganet commented Jan 21, 2013

ageDifference?

Member

nickl- commented Jan 30, 2013

ageDiff ?

Owner

henriquemoody commented Jan 30, 2013

No, I thinks age is better.
+1 for age

Contributor

caferrari commented Jan 30, 2013

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.

Owner

alganet commented Jan 30, 2013

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)

Contributor

caferrari commented Jan 30, 2013

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)

@augustohp augustohp added the BC Break label Feb 16, 2014

@augustohp augustohp added this to the Backlog milestone Feb 16, 2014

Owner

augustohp commented Feb 16, 2014

I've update the issue description to easy contributions and resume discussion until now.

@augustohp augustohp modified the milestones: 0.7.0, Backlog, 0.6.1, 0.6.0 Feb 17, 2014

malukenho added a commit to malukenho/Validation that referenced this issue Feb 18, 2014

malukenho added a commit to malukenho/Validation that referenced this issue Feb 20, 2014

malukenho added a commit to malukenho/Validation that referenced this issue Feb 20, 2014

malukenho added a commit to malukenho/Validation that referenced this issue May 9, 2014

@augustohp augustohp modified the milestones: 0.7.0, 0.6.0 Jun 26, 2014

@malukenho malukenho referenced this issue Jul 11, 2014

Closed

Add rule "Age" to validation. #150

3 of 6 tasks complete

@henriquemoody henriquemoody modified the milestone: 0.7.0 Jan 7, 2015

@henriquemoody henriquemoody modified the milestones: 0.8, Backlog Feb 11, 2015

Owner

henriquemoody commented Feb 19, 2015

This rule is going to be available in 9.0 version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment