aboutsummaryrefslogtreecommitdiff
path: root/src/client/Utils/Validation.elm
blob: b9bccb3e8d509c0cc8912f9c761a4ab1c2555a56 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
module Utils.Validation
  ( validateNonEmpty
  , validateNumber
  ) where

import String
import Reads exposing (readInt)

validateNonEmpty : String -> String -> Result String String
validateNonEmpty message str =
  if String.isEmpty str
   then Err message
   else Ok str

validateNumber : String -> (Int -> Bool) -> String -> Result String Int
validateNumber message numberForm str =
  case readInt str of
    Just number ->
      if numberForm number
        then Ok number
        else Err message
    Nothing ->
      Err message