validate-0.0: Validate

Data.Validate

Contents

Description

Validate values, such as common user inputs; emails, age, address, credit card, web address, etc.

Synopsis

Documentation

type Test e a b = Maybe a -> Input e (Maybe b)Source

A test taking input and producing a new input.

Validation

validateSource

Arguments

:: Str e 
=> Test e a b

Test to perform.

-> a

Value on which to perform the test.

-> Maybe [e]

Maybe a list of errors, or Nothing, meaning success.

Validate some input with testing function.

Testing utilities

testSource

Arguments

:: Str e 
=> e

Error if predicate fails.

-> (a -> Bool)

Predicate to test the value with.

-> Test e a a

A test from a to a.

A generic testing function with a predicate, with type preservation.

labelSource

Arguments

:: Str e 
=> e

Error message to attach if test fails.

-> Test e a b

Test whose result is checked for failure.

-> Test e a b

A new test from a to b which shows the label as an error on failure.

Attach a "label" around a testing function which errors. This might be useless.

Testing functions

equal :: (Show a, Eq a, Str e) => a -> Test e a aSource

Is equal to something.

isInt :: Str e => Test e e eSource

Check that a String contains an integer.

lessSource

Arguments

:: (Str e, Ord a, Show a) 
=> a

Something which the value being test must be less than.

-> Test e a a

A test from a to a which tests this property.

Check that a a value is less than a specified value.

more :: (Str e, Ord a, Show a) => a -> Test e a aSource

Like less but the value must be more than the specified value.

age :: (Str e, Str s) => Test e s IntSource

Test that a given age is correct (130 years of age max.). http:www.seniorjournal.comNEWSSeniorStats/5-12-03-NoOne123.htm

email :: (Str e, Str s) => Test e s sSource

Test that a given email is correct. Based on http:www.hm2k.compostswhat-is-a-valid-email-address

patternSource

Arguments

:: (Str e, Str s) 
=> e

An error message if the match fails.

-> s

The regular expression

-> Test e s s

The produced testing function.

Make a test which tests a string according to a regular expression pattern.

Conversion functions

int :: (Str e, Str s) => Test e s IntSource

Check that a string contains an integer, and try to convert to an Int.

float :: (Str e, Str s) => Test e s FloatSource

Check that a string contains an integer, and try to convert to a Float.