Form validation doesn’t need to be difficult or require a significant amount of code. Using elm-validate will simplify your validation and increase code reuse throughout your application.
validate : Model -> List String
validate model =
[ .password >> Validate.ifBlank "Password cannot be blank"
, .password >> ifLengthLessThan 8 "Password must be 8+ characters"
, .email >> Validate.ifInvalidEmail "Email address is invalid"
, .age >> Validate.ifNotInt "Age must be a number"
ifLengthLessThan : Int -> error -> Validate.Validator error String
ifLengthLessThan minLength err =
(String.length string) < minLength