Patterns for some maps passed to the functions as arguments:
key | value | description | mandatory extra key | optional extra key |
---|---|---|---|---|
:validate/type | :validate/mandatory | validates if field is present | - | :validate/message ^string with %s being field name |
:validate/type | :validate/max | validates if max is not reached | :validate/value ˆint | :validate/message ^string with 1st %s being field name, 2nd being max value |
:validate/type | :validate/min | validates if at least min value is reached | :validate/value ˆint | :validate/message ^string with 1st %s being field name, 2nd being min value |
:validate/type | :validate/regex | validates if string matches regex pattern | :validate/value ˆregex | :validate/message ^string with %s being field name |
:validate/type | :validate/custom | validates if custom fn receiving the value returns true | :validate/value ^fn | :validate/message ^string with %s being field name |
- Examples:
{"field-name"
[{:validate/type :validate/mandatory, :validate/message "%s is ..."},
{:validate/type :validate/min, :validate/value 12, :validate/message "%s is mandatory"},
{:validate/type :validate/max, :validate/value 40, :validate/message "%s is ..."},
{:validate/type :validate/regex, :validate/value #"^[\d]{1,2}$", :validate/message "%s is ..."},
{:validate/type :validate/custom, :validate/value fn, :validate/message "% is ..."}]}
(validate
{:name "Rosa"}
{"age" [{:validate/type :validate/mandatory}]})
;=> ExceptionInfo thrown => ExceptionInfo{data {:type :bad-format
; :validation-messages [{:field "age"
; :message "Field age is not present"}]}}
(validate
{:name "Rosa" :age 17}
{"age" [{:validate/type :validate/min, :validate/value 18}]})
;=> ExceptionInfo thrown => ExceptionInfo{data {:type :bad-format
; :validation-messages [{:field "age"
; :message "Field age must have a minimum size of 18"}]}}
Can you improve this documentation?Edit on GitHub
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close