From 902acfbdbcc1d59941399753e887479e586e2748 Mon Sep 17 00:00:00 2001 From: Joris Date: Sun, 26 Mar 2017 23:16:28 +0200 Subject: Improve form validation - Trim names - Income amount accepted from 0 - Validate colors --- src/client/Validation.elm | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'src/client/Validation.elm') 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 -- cgit v1.2.3