rtfeldman / elm-validate

Convenience functions for validating Elm data.
http://package.elm-lang.org/packages/rtfeldman/elm-validate/latest
BSD 3-Clause "New" or "Revised" License
145 stars 28 forks source link

Validade if an Int is between a range (e.g. between 18 and 60) #34

Closed lisardo closed 6 years ago

lisardo commented 6 years ago

I'm trying to figure out a way to create a Validator if an Int is between a specific range (e.g. 18 and 120).

The real life use case is to validate age of people.

Is there a way this can be done in the new version of the library?

lisardo commented 6 years ago

I got it working:

ifInRange : Int -> Int -> (subject -> Int) -> error -> Validator error subject
ifInRange min max subjectToInt error =
   ifFalse (\subject -> (subjectToInt subject) >= min && (subjectToInt subject) <= max) error

Ellie example

I'll close the issue.