GithubHelp home page GithubHelp logo

Comments (13)

augustohp avatar augustohp commented on May 8, 2024

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.

Petah avatar Petah commented on May 8, 2024

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

henriquemoody avatar henriquemoody commented on May 8, 2024

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

alganet avatar alganet commented on May 8, 2024

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.

henriquemoody avatar henriquemoody commented on May 8, 2024

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

from validation.

alganet avatar alganet commented on May 8, 2024

ageDifference?

from validation.

nickl- avatar nickl- commented on May 8, 2024

ageDiff ?

from validation.

henriquemoody avatar henriquemoody commented on May 8, 2024

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

from validation.

caferrari avatar caferrari commented on May 8, 2024

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.

alganet avatar alganet commented on May 8, 2024

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.

caferrari avatar caferrari commented on May 8, 2024

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.

augustohp avatar augustohp commented on May 8, 2024

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

from validation.

henriquemoody avatar henriquemoody commented on May 8, 2024

This rule is going to be available in 9.0 version.

from validation.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.