Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create age validator (Deprecates minimumAge) #103

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

Create age validator (Deprecates minimumAge) #103

Petah opened this issue Jan 13, 2013 · 13 comments

Comments

@Petah
Copy link

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?

@augustohp
Copy link
Member

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
Copy link
Author

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.

@henriquemoody
Copy link
Member

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

@alganet
Copy link
Member

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?

@henriquemoody
Copy link
Member

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

@alganet
Copy link
Member

alganet commented Jan 21, 2013

ageDifference?

@nickl-
Copy link
Member

nickl- commented Jan 30, 2013

ageDiff ?

@henriquemoody
Copy link
Member

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

@caferrari
Copy link
Contributor

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.

@alganet
Copy link
Member

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)

@caferrari
Copy link
Contributor

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 this to the Backlog milestone Feb 16, 2014
@augustohp
Copy link
Member

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 pushed a commit to malukenho/Validation that referenced this issue Feb 18, 2014
malukenho pushed a commit to malukenho/Validation that referenced this issue Feb 20, 2014
malukenho pushed a commit to malukenho/Validation that referenced this issue Feb 20, 2014
malukenho pushed 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
@henriquemoody henriquemoody modified the milestone: 0.7.0 Jan 7, 2015
@henriquemoody henriquemoody added this to the 0.8 milestone Feb 11, 2015
@henriquemoody
Copy link
Member

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
Projects
None yet
Development

No branches or pull requests

6 participants