validate-input: Input validation combinator library

[ library, mit, web ] [ Propose Tags ] [ Report a vulnerability ]

A small Haskell combinator library that provides a simple way of validating user provided data structures.


[Skip to Readme]

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

  • No Candidates
Versions [RSS] 0.1.0.0, 0.2.0.0, 0.3.0.0, 0.4.0.0, 0.5.0.0
Dependencies base (>=4.6 && <5), bytestring (>=0.10), mtl (>=2.1), pcre-heavy (>=1.0), semigroups (>=0.16), string-conversions (>=0.4), text (>=1.2), transformers [details]
Tested with ghc ==8.8.4
License MIT
Copyright (c) 2015-2021 Alexander Thiemann
Author Alexander Thiemann <mail@athiemann.net>
Maintainer Alexander Thiemann <mail@athiemann.net>
Category Web
Home page https://github.com/agrafix/validate-input
Bug tracker https://github.com/agrafix/validate-input/issues
Source repo head: git clone https://github.com/agrafix/validate-input
Uploaded by AlexanderThiemann at 2021-02-07T01:37:14Z
Distributions LTSHaskell:0.5.0.0, NixOS:0.5.0.0, Stackage:0.5.0.0
Reverse Dependencies 1 direct, 0 indirect [details]
Downloads 3454 total (14 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs available [build log]
Last success reported on 2021-02-07 [all 1 reports]

Readme for validate-input-0.5.0.0

[back to package description]

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
   , ex_friendName :: Maybe T.Text
   } deriving (Show)

data ExampleChecked
   = ExampleChecked
   { exc_username :: T.Text
   , exc_dogs :: Int
   , exc_friendName :: T.Text
   } 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 => TransValidationRuleT String m Example ExampleChecked
checkExample e =
    ExampleChecked
    <$> checkUsername (ex_username e)
    <*> checkNumber (ex_dogs e)
    <*> requiredValue "You must provide a friend name!" (ex_friendName e)

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

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

  • 8.8.4

License

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