-
Notifications
You must be signed in to change notification settings - Fork 0
/
validators.cljs
47 lines (39 loc) · 1.26 KB
/
validators.cljs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
(ns re-val.validators
(:require [cljs-time.core :as t]
[cljs-time.format :as fmt]
[reagent.core :as r]
[taoensso.timbre :as timbre
:refer-macros (log trace debug info warn error fatal report
logf tracef debugf infof warnf errorf fatalf reportf
spy get-env log-env)]))
;;TODO i18n
(defn required-validator
[s k db]
(if (or (nil? s)
(and (string? s)
(= "" (clojure.string/trim s))))
[false "dit veld is verplicht"]
[true ]))
(defn something-selected-validator
[s k db]
(if (or
(= "-- selecteer --" s)
(nil? s)
(= "" s))
[false "dit veld is verplicht."]
[true ]))
(defn checked-validator
[s k db]
(debug s)
(if (and (not (nil? s)) (boolean? s) s)
[true ]
[false "dit veld moet geselecteerd zijn."]))
(defn valid-email?
[email]
(let [pattern #"[a-zA-Z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-zA-Z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?\.)+[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?"]
(and (string? email) (re-matches pattern email))))
(defn email-validator
[s k db]
(if (valid-email? s)
[true]
[false "Dit is geen geldig e-mailadres."]))