aboutsummaryrefslogtreecommitdiff
path: root/src/client/Validation.elm
diff options
context:
space:
mode:
authorJoris2017-03-26 23:16:28 +0200
committerJoris2017-03-27 00:17:41 +0200
commit902acfbdbcc1d59941399753e887479e586e2748 (patch)
tree0ad90ead3f8bdf0ea7c94462d1577c8e188df469 /src/client/Validation.elm
parent8062f1c9c34e9b25d76b22bd6ba2a1a99666279b (diff)
downloadbudget-902acfbdbcc1d59941399753e887479e586e2748.tar.gz
budget-902acfbdbcc1d59941399753e887479e586e2748.tar.bz2
budget-902acfbdbcc1d59941399753e887479e586e2748.zip
Improve form validation
- Trim names - Income amount accepted from 0 - Validate colors
Diffstat (limited to 'src/client/Validation.elm')
-rw-r--r--src/client/Validation.elm18
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