aboutsummaryrefslogtreecommitdiff
path: root/src/client/Utils/Validation.elm
blob: 0c1773e967078d082609b0e3e61989bbb5a1259f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
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 -> String -> Result String Int
validateNumber message str =
  case readInt str of
    Just number ->
      Ok number
    Nothing ->
      Err message