diff options
author | Joris Guyonvarch | 2015-08-14 17:43:10 +0200 |
---|---|---|
committer | Joris Guyonvarch | 2015-08-14 17:43:10 +0200 |
commit | 965c0f57875e27fd09df2fc72487f4651addb79b (patch) | |
tree | 3123597112e990fe06405557485e664d3a8da5f3 /src/client | |
parent | 006d54bf4ac4dd9e05d62d0007759f28740fd77a (diff) |
Cost must not be negative
Diffstat (limited to 'src/client')
-rw-r--r-- | src/client/Model/View/Payment/Add.elm | 2 | ||||
-rw-r--r-- | src/client/Utils/Validation.elm | 8 |
2 files changed, 6 insertions, 4 deletions
diff --git a/src/client/Model/View/Payment/Add.elm b/src/client/Model/View/Payment/Add.elm index 5428c3d..5ab7a40 100644 --- a/src/client/Model/View/Payment/Add.elm +++ b/src/client/Model/View/Payment/Add.elm @@ -35,4 +35,4 @@ validateCost : String -> Translations -> Result String Int validateCost cost translations = cost |> validateNonEmpty (getMessage "CostRequired" translations) - |> flip Result.andThen (validateNumber (getMessage "CostMustBeNumber" translations)) + |> flip Result.andThen (validateNumber (getMessage "CostMustBeNumber" translations) (\number -> number >= 0)) diff --git a/src/client/Utils/Validation.elm b/src/client/Utils/Validation.elm index 0c1773e..b9bccb3 100644 --- a/src/client/Utils/Validation.elm +++ b/src/client/Utils/Validation.elm @@ -12,10 +12,12 @@ validateNonEmpty message str = then Err message else Ok str -validateNumber : String -> String -> Result String Int -validateNumber message str = +validateNumber : String -> (Int -> Bool) -> String -> Result String Int +validateNumber message numberForm str = case readInt str of Just number -> - Ok number + if numberForm number + then Ok number + else Err message Nothing -> Err message |