diff options
Diffstat (limited to 'src/client/Validation.elm')
-rw-r--r-- | src/client/Validation.elm | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/src/client/Validation.elm b/src/client/Validation.elm index 4781c3d..de27963 100644 --- a/src/client/Validation.elm +++ b/src/client/Validation.elm @@ -2,15 +2,19 @@ module Validation exposing ( cost , date , category + , color + , new ) import Date exposing (Date) import Date.Extra.Core exposing (intToMonth) import Date.Extra.Create exposing (dateFromFields) import Dict +import Regex import String exposing (toInt, split) import Form.Validate as Validate exposing (Validation) +import Form.Error as Error exposing (ErrorValue(CustomError)) import Model.Category exposing (Categories, CategoryId) @@ -45,3 +49,17 @@ category categories = Err _ -> Err (Validate.customError "InvalidCategory") ) + +color : Validation String String +color = + Validate.customValidation Validate.string (\str -> + if Regex.contains (Regex.regex "^#[0-9a-fA-F]{6}$") str + then Ok str + else Err (Validate.customError "InvalidColor") + ) + +new : List x -> x -> Validation String x +new xs x field = + if List.member x xs + then Err (Error.value <| CustomError "AlreadyExists") + else Ok x |