API for noir.validation
- ()
Usage:
(ns your-namespace
(:require noir.validation))
Overview
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.
Public Variables and Functions
errors?
function
Usage: (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
function
Usage: (get-errors field)
Get the errors for the given field. This will return a vector of all error strings or nil.
has-value?
function
Usage: (has-value? v)
Returns true if v is truthy and not an empty string.
has-values?
function
Usage: (has-values? coll)
Returns true if all members of the collection has-value? This works on maps as well.
is-email?
function
Usage: (is-email? v)
Returns true if v is an email address
max-length?
function
Usage: (max-length? v len)
Returns true if v is less than or equal to the given len
min-length?
function
Usage: (min-length? v len)
Returns true if v is greater than or equal to the given len
not-nil?
function
Usage: (not-nil? v)
Returns true if v is not nil
on-error
function
Usage: (on-error field func)
If the given field has an error, execute func and return its value
rule
function
Usage: (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
function
Usage: (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.