This library provides a few functions for validating data.
Return an Err errorMessage if the given value isn't positive float number,
otherwise return Ok value. It contains also float validation of value.
Return 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 "It is not int number!"
intValidation "108" -- Ok 108
intValidation "3.14" -- Err "It is not int number!"Return an Err errorMessage if the given value isn't positive int number,
otherwise return Ok value. It contains also int validation of value.
Return an Err errorMessage if the given string is empty, otherwise
return Ok value.
Return an Err errorMessage if the given string isn't correct an email address,
otherwise return Ok value.
Return an Err errorMessage if the given string isn't correct an url path,
otherwise return Ok value.
Return 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!"Return an Err errorMessage if the given boolean value is false, otherwise
return Ok True.
Validate Field
Return 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."Return 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
Return an
Err errorMessageif the given value isn't float number, otherwise returnOk value.