MyNixOS website logo
Description

Input validation combinator library.

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

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.

Metadata

Version

0.5.0.0

License

Platforms (77)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-freebsd
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64-windows
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-darwin
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-darwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows