@hackage validate-input0.3.0.0

Input validation combinator library

validate-input

Build Status Hackage

Intro

Hackage: validate-input Stackage: validate-input

Input validation combinator library

Library Usage Example

{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE QuasiQuotes #-}
import Data.Validator
import qualified Data.Text as T

data Example
   = Example
   { ex_username :: T.Text
   , ex_dogs :: Int
   } deriving (Show)

main :: IO ()
main =
    do putStrLn "Check results:"
       print example

checkUsername :: Monad m => ValidationRuleT String m T.Text
checkUsername =
    lengthBetween 3 12 "Should between 3 and 12 chars"
    >=> matchesRegex [re|^[A-za-z0-9]+$|] "only alpha num"

checkNumber :: Monad m => ValidationRuleT String m Int
checkNumber =
    smallerThan 5 "No more than 5 dogs allowed"

checkExample :: Monad m => ValidationRuleT String m Example
checkExample e =
    Example <$> checkUsername (ex_username e)
            <*> checkNumber (ex_dogs e)

example :: Either String Example
example =
    runValidator checkExample $
    Example
    { ex_username = "alex"
    , ex_dogs = 23
    }

Install

  • Using cabal: cabal install validate-input
  • Using Stack: stack install validate-input
  • From Source (cabal): git clone https://github.com/agrafix/validate-input.git && cd validate-input && cabal install
  • From Source (stack): git clone https://github.com/agrafix/validate-input.git && cd validate-input && stack build

Misc

Supported GHC Versions

  • 7.8.4
  • 7.10.2

License

Released under the MIT license. (c) 2015 Alexander Thiemann