This library provides a few functions for validating data.
Returns an Err errorMessage if the given value isn't int number, otherwise
return Ok value.
import Validation exposing (Validator, ErrorMessage)
intValidation : Validator String Int
intValidation =
isInt "The value is not int number!"
intValidation "108" -- Ok 108
intValidation "3.14" -- Err "It is not int number!"Returns an Err errorMessage2 or Err errorMessage1 if the given value isn't
greater or equal to defined value (defined by user) or if first validation failed.
Otherwise return Ok value.
Returns an Err errorMessage2 or Err errorMessage1 if the given value isn't
less or equal to defined value (defined by user) or if first validation failed.
Otherwise return Ok value.
Returns an Err errorMessage2 or Err errorMessage1 if the given value isn't
greater than defined value (defined by user) or if first validation failed.
Otherwise return Ok value.
Returns an Err errorMessage2 or Err errorMessage1 if the given value isn't
less than defined value (defined by user) or if first validation failed.
Otherwise return Ok value.
import Validation exposing (ErrorMessage, Validator, isLessThan)
isLessThanInt : Validator String Int
isLessThanInt =
isLessThan (isInt "The value is not int number!") 5 "The value is not less than 5!"
isLessThanInt "3" -- Ok 3
isLessThanInt "6" -- Err "The value is not less than 5!"
isLessThanInt "6.3" -- Err "The value is not int number!"Returns an Err errorMessage2 or Err errorMessage1 if the given value isn't
in range (mathematically speaking it's closed interval) or if first validation failed.
Otherwise return Ok value. First number has to be less than second.
import Validation exposing (ErrorMessage, Validator, isRange)
floatRange : Validator String Float
floatRange =
isRange (isFloat "The value is not float number!") 0 5.5 "The value is not in range!"
floatRange "3.8" -- Ok 3.8
floatRange "6.1" -- Err "The value is not in range!"
floatRange "6.x" -- Err "The value is not float number!"Returns an Err errorMessage if the given string is empty, otherwise
return Ok value.
Returns an Err errorMessage if the given string isn't correct an email address,
otherwise return Ok value.
Returns an Err errorMessage if the given string isn't correct an url path,
otherwise return Ok value.
Returns an Err errorMessage if the given value isn't in list, otherwise
return Ok value.
import Validation exposing (Validator, ErrorMessage)
elInListValidation : Validator (Int, List Int) Int
elInListValidation =
isInList "Given value is not in list!"
elInListValidation (3, [1, 2, 3]) -- Ok 3
elInListValidation (5, [1, 2, 3]) -- Err "Given value is not in list!"Returns an Err errorMessage if the given boolean value is false, otherwise
return Ok True.
Validate Field
Returns an Err errorMessage if the given value of Field Valid a isn't same as
validation argument, otherwise return Ok validation argument for others Validity
or for Valid a is Ok value.
import Validation exposing (Validator, ErrorMessage, Field)
pass : Field String String
pass =
Field "" (Valid "password*")
confirmPasswordValidation : Validator String String
confirmPasswordValidation =
isEqualTo pass "The passwords don't match."
confirmPasswordValidation "password*" -- Ok "password*"
confirmPasswordValidation "pasword*" -- Err "The passwords don't match."Returns false if Field hasn't validity Valid a, otherwise
return true.
import Validation exposing (Field, field, preValidatedField)
intNotValidValue = field "50" -- Field "50" NotValidated
intValidValue = preValidatedField 50 -- Field "50" (Valid 50)
isValidField intNotValidValue -- False
isValidField intValidValue -- True
Returns an
Err errorMessageif the given value isn't float number, otherwise returnOk value.