noir.validation documentation

Functions for validating input and setting string errors on fields.
All fields are simply keys, meaning this can be a general error storage and
retrieval mechanism for the lifetime of a single request. Errors are not
persisted and are cleaned out at the end of the request.

errors?

(errors? & field)
For all fields given return true if any field contains errors. If none of the fields
contain errors, return false. If no fields are supplied return true if any errors exist.

get-errors

(get-errors & [field])
Get the errors for the given field. This will return a vector of all error strings or nil.

has-value?

(has-value? v)
Returns true if v is truthy and not an empty string.

has-values?

(has-values? coll)
Returns true if all members of the collection has-value? This works on maps as well.

is-email?

(is-email? v)
Returns true if v is an email address

max-length?

(max-length? v len)
Returns true if v is less than or equal to the given len

min-length?

(min-length? v len)
Returns true if v is greater than or equal to the given len

not-nil?

(not-nil? v)
Returns true if v is not nil

on-error

(on-error field func)
If the given field has an error, execute func and return its value

rule

(rule passed? [field error])
If the passed? condition is not met, add the error text to the given field:
(rule (not-nil? username) [:username "Usernames must have a value."])

set-error

(set-error field error)
Explicitly set an error for the given field. This can be used to
create complex error cases, such as in a multi-step login process.