diff options
author | Joris | 2016-01-03 23:37:14 +0100 |
---|---|---|
committer | Joris | 2016-01-03 23:46:19 +0100 |
commit | d9df5c3fcffe12aac239b58ccf2fd82c19c3be62 (patch) | |
tree | aee62828e85c9d30e2beb5954062942f0d5d53f4 /src/server/Validation.hs | |
parent | d22d10da342520163014dda255d5d9bd5e1a80c0 (diff) | |
download | budget-d9df5c3fcffe12aac239b58ccf2fd82c19c3be62.tar.gz budget-d9df5c3fcffe12aac239b58ccf2fd82c19c3be62.tar.bz2 budget-d9df5c3fcffe12aac239b58ccf2fd82c19c3be62.zip |
Validate add payment server side
Diffstat (limited to 'src/server/Validation.hs')
-rw-r--r-- | src/server/Validation.hs | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/src/server/Validation.hs b/src/server/Validation.hs new file mode 100644 index 0000000..9035be7 --- /dev/null +++ b/src/server/Validation.hs @@ -0,0 +1,23 @@ +module Validation + ( nonEmpty + , number + ) where + +import Data.Text (Text) +import qualified Data.Text as T + +nonEmpty :: a -> Text -> Either a Text +nonEmpty x str = + if T.null str + then Left x + else Right str + +number :: x -> (Int -> Bool) -> Text -> Either x Int +number x numberForm str = + case reads (T.unpack str) :: [(Int, String)] of + (number, _) : _ -> + if numberForm number + then Right number + else Left x + _ -> + Left x |