The core namespace contains all of the built in validators and the defvalidator macro.
The only other public functions are
validation-set
validate
valid?
results
as-validator
You can view more information in the [readme] (https://github.com/markwoodhall/clova/blob/master/README.md). There are also example validation scenarios here.
The API documentation is available here.
You can also view [blog posts] (http://markw.xyz/tags/clova/) about clova.
The core namespace contains all of the built in validators and the defvalidator macro. The only other public functions are - `validation-set` - `validate` - `valid?` - `results` - `as-validator` You can view more information in the [readme] (https://github.com/markwoodhall/clova/blob/master/README.md). There are also example validation scenarios [here](http://markwoodhall.github.io/clova/EXAMPLES.html). The API documentation is available [here](http://markwoodhall.github.io/clova/). You can also view [blog posts] (http://markw.xyz/tags/clova/) about clova.
(=? value v)
Check an input value to see if it is equal to v using the regular =
function.
It is worthwhile using =date?
for validating date equality, since it has support
for parsing string dates and comparing DateTime objects.
Check an input value to see if it is equal to v using the regular `=` function. It is worthwhile using [[=date?]] for validating date equality, since it has support for parsing string dates and comparing DateTime objects.
(=date? value d & [opt])
Check an input value to see if it is chronoligically equal to d. Where
d is either the string representation of a date or one of [java.util.Date org.joda.time.DateTime]
or
[js/Date goog.date.Date goog.date.DateTime]
Optionally, takes a map argument and makes use of the following keys:
:formatter
You can use one of the built in ISO8601 formatters
from clj-time or cljs-time. You can also define your own custom format string.Check an input value to see if it is chronoligically equal to d. Where d is either the string representation of a date or one of `[java.util.Date org.joda.time.DateTime]` or `[js/Date goog.date.Date goog.date.DateTime]` Optionally, takes a map argument and makes use of the following keys: - `:formatter` You can use one of the built in ISO8601 formatters from clj-time or cljs-time. You can also define your own custom format string.
(after? value d & [opt])
Check an input value to see if it is chronoligically after d. Where
d is either the string representation of a date or one of [java.util.Date org.joda.time.DateTime]
or
[js/Date goog.date.Date goog.date.DateTime]
Optionally, takes a map argument and makes use of the following keys:
:formatter
You can use one of the built in ISO8601 formatters
from clj-time or cljs-time. You can also define your own custom format string.Check an input value to see if it is chronoligically after d. Where d is either the string representation of a date or one of `[java.util.Date org.joda.time.DateTime]` or `[js/Date goog.date.Date goog.date.DateTime]` Optionally, takes a map argument and makes use of the following keys: - `:formatter` You can use one of the built in ISO8601 formatters from clj-time or cljs-time. You can also define your own custom format string.
(all? value col)
Check an input value to see if it matches a given collection of predicates. Predicates can be concrete values or they can be functions, they can be single items or collections.
(all? true [true (fn [v] (= true v))])
(all? true (fn [v] (= true v)))
Check an input value to see if it matches a given collection of predicates. Predicates can be concrete values or they can be functions, they can be single items or collections. `(all? true [true (fn [v] (= true v))])` `(all? true (fn [v] (= true v)))`
(alphanumeric? value)
Checks an input value to see if it is alphanumeric. Alphanumeric
is defined as [a-zA-Z0-9*$]
, if you need to customise this you can use the
matches?
validator with a custom regex.
Checks an input value to see if it is alphanumeric. Alphanumeric is defined as `[a-zA-Z0-9*$]`, if you need to customise this you can use the [[matches?]] validator with a custom regex.
(as-validator f)
(as-validator f
{:keys [default-message allow-missing-key?]
:or {default-message "%s is %s but this is not a valid value."
allow-missing-key? true}
:as m})
Takes a function f and applies optional m as meta data around it. f should be accept a first argument as the value to validate.
When m is present the following keys are taken and used as meta data to declare a validator:
:default-message
The default message template to be used when validation fails.:allow-missing-key?
Should validation fail if the :target
key is not present.When m is not specified suitable defaults are used.
Takes a function f and applies optional m as meta data around it. f should be accept a first argument as the value to validate. When m is present the following keys are taken and used as meta data to declare a validator: - `:default-message` The default message template to be used when validation fails. - `:allow-missing-key?` Should validation fail if the `:target` key is not present. When m is not specified suitable defaults are used.
(before? value d & [opt])
Check an input value to see if it is chronoligically before d. Where
d is either the string representation of a date or one of [java.util.Date org.joda.time.DateTime]
or
[js/Date goog.date.Date goog.date.DateTime]
Optionally, takes a map argument and makes use of the following keys:
:formatter
You can use one of the built in ISO8601 formatters
from clj-time or cljs-time. You can also define your own custom format string.Check an input value to see if it is chronoligically before d. Where d is either the string representation of a date or one of `[java.util.Date org.joda.time.DateTime]` or `[js/Date goog.date.Date goog.date.DateTime]` Optionally, takes a map argument and makes use of the following keys: - `:formatter` You can use one of the built in ISO8601 formatters from clj-time or cljs-time. You can also define your own custom format string.
(between? value lower upper)
Checks an input value to see if it is between lower and upper.
Checks an input value to see if it is between lower and upper.
(credit-card? value)
Chacks an input value to see if it is a "valid" credit card number based on the Luhn algorithm.
Chacks an input value to see if it is a "valid" credit card number based on the Luhn algorithm.
(date? value & [opt])
Checks an input value to see if it is a date.
If value is a string then it is parsed using clj-time
or cljs-time
.
If value is not a string but is one of [java.util.Date org.joda.time.DateTime]
or
[js/Date goog.date.Date goog.date.DateTime]
then it will be considered a date?
.
Optionally, takes a map argument and makes use of the following keys:
:formatter
You can use one of the built in ISO8601 formatters
from clj-time or cljs-time. You can also define your own custom format string.Checks an input value to see if it is a date. If value is a string then it is parsed using `clj-time` or `cljs-time`. If value is not a string but is one of `[java.util.Date org.joda.time.DateTime]` or `[js/Date goog.date.Date goog.date.DateTime]` then it will be considered a `date?`. Optionally, takes a map argument and makes use of the following keys: - `:formatter` You can use one of the built in ISO8601 formatters from clj-time or cljs-time. You can also define your own custom format string.
(defvalidator doc-string fname validator-meta-data args & body)
(defvalidator &form &env doc-string fname validator-meta-data args & body)
Wraps body in a function and defines it with meta data
used to support the validation process.
Works using a similar pattern to defn
.
Wraps body in a function and defines it with meta data used to support the validation process. Works using a similar pattern to `defn`.
(email? value)
Checks an input value to see if it is a valid email address
Checks an input value to see if it is a valid email address
(exists? value col)
Checks for the presence of an item in a collection.
Checks for the presence of an item in a collection.
(greater? value lower)
Checks an input value to see if it is greater than lower.
Checks an input value to see if it is greater than lower.
(length? value l)
Check an input value to see if it has a length equal to l. Work on sequences and strings.
Check an input value to see if it has a length equal to l. Work on sequences and strings.
(lesser? value lower)
Checks an input value to see if it is less than lower.
Checks an input value to see if it is less than lower.
(longer? value l)
Check an input value to see if it has a length longer than l. Work on sequences and strings.
Check an input value to see if it has a length longer than l. Work on sequences and strings.
(matches? value regex)
Checks a string representation of value against regex and returns true if value matches the regex. If value is not a match then returns nil.
Checks a string representation of value against regex and returns true if value matches the regex. If value is not a match then returns nil.
(negative? value)
Checks an input value to see if it is a negative number.
Checks an input value to see if it is a negative number.
(not-exists? value col)
Checks for the non presence of an item in a collection.
Checks for the non presence of an item in a collection.
(not-nil? value)
Checks for the presence of a non nil value.
Checks for the presence of a non nil value.
(numeric? value)
Checks an input value to see if it is numeric.
Checks an input value to see if it is numeric.
(one-of? value col)
Checks an input value to see if it is one of the items in a col
Checks an input value to see if it is one of the items in a col
(positive? value)
Checks an input value to see if it is a positive number.
Checks an input value to see if it is a positive number.
(post-code? value)
Checks an input value to see if it is a valid uk post code.
Checks an input value to see if it is a valid uk post code.
(required? value)
Checks for the presence of a key based on the default value of ::key-not-found?
for a missing key.
Checks for the presence of a key based on the default value of `::key-not-found?` for a missing key.
(results v-set m)
Takes a validation set and applies it to m. This is just a shorthand method over the validate function and returns only the validation results.
Takes a validation set and applies it to m. This is just a shorthand method over the validate function and returns only the validation results.
(shorter? value l)
Check an input value to see if it has a length shorter than l. Work on sequences and strings.
Check an input value to see if it has a length shorter than l. Work on sequences and strings.
(stringy? value)
Checks an input value to see if it is a string
Checks an input value to see if it is a string
(url? value)
Checks an input value to see if it is a valid url.
Checks an input value to see if it is a valid url.
(valid? v-set m)
Takes a validation set and applies it to m. This is just a shorthand method over the validate function and returns only a truthy or falsy value indicating the validation status.
Takes a validation set and applies it to m. This is just a shorthand method over the validate function and returns only a truthy or falsy value indicating the validation status.
(validate v-set m)
(validate v-set
m
{:keys [default-message-fn short-circuit?]
:or {default-message-fn (fn [v-type value args] nil)
short-circuit? false}})
Takes a validation set and applies it to m.
Returns the original map m transposed with error messages for non validating keys, also adds :clova.core/valid?
with either a truthy or falsy value and
:clova.core/results
which is a sequence of validation failure messages, if applicable.
Optionally takes a map of options:
:default-message-fn
can be specified to override the default validation messages. If specified
the function will be called and receive the validator type as an argument. If the result of calling
the function is anything but nil it will be used as the default validation message.
:short-circuit?
when true no further validators for the validation set will be processed.
The default is false and therefore to process all validators.
Takes a validation set and applies it to m. Returns the original map m transposed with error messages for non validating keys, also adds `:clova.core/valid?` with either a truthy or falsy value and `:clova.core/results` which is a sequence of validation failure messages, if applicable. Optionally takes a map of options: `:default-message-fn` can be specified to override the default validation messages. If specified the function will be called and receive the validator type as an argument. If the result of calling the function is anything but nil it will be used as the default validation message. `:short-circuit?` when true no further validators for the validation set will be processed. The default is false and therefore to process all validators.
(validation-set col)
Takes a sequence (col) that represents keys to validate and the functions used to validate them.
e.g. [:email email? :post-code post-code?]
It is also possible to specify keys to traverse nested maps.
e.g. using [[:user :credentials :name] [matches? #"someregex"]]
we can define a validation function to target the :name
key in a map like
{:user {:credentials {:name "username" }}}
Returns a sequence of functions merged with meta data used by the validation.
Takes a sequence (col) that represents keys to validate and the functions used to validate them. e.g. `[:email email? :post-code post-code?]` It is also possible to specify keys to traverse nested maps. e.g. using `[[:user :credentials :name] [matches? #"someregex"]]` we can define a validation function to target the `:name` key in a map like `{:user {:credentials {:name "username" }}}` Returns a sequence of functions merged with meta data used by the validation.
(zip-code? value)
Checks an input value to see if it is a valid zip code.
Checks an input value to see if it is a valid zip code.
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close