Description Usage Arguments Details Value References See Also Examples
A field validation assigns a series of rules that have been assigned to a particular input and checks, upon the form submission, whether or not the input meets all specified criteria.
1 2 3 | field_validation(id, ..., extra_params = NULL)
field_rule(rule, prompt = NULL, value = NULL)
|
id |
HTML id of the field to be validated |
... |
A series of |
extra_params |
A named list of extra parameters that can be added to the field validation. For example
|
rule |
The type of rule to be applied. Valid rules are available in Details. |
prompt |
Text to be displayed in the UI if the validation fails. Leave |
value |
Certain fields require a value to check validation. Check Details if the |
If it fails, then the field will be highlighted and the failures will either be specified as a message below the field or a label. Once the failure(s) has been rectified, the highlighting will disappear.
The following rules
are allowed:
empty
A field is not empty
checked
A checkbox field is checked
email
A field is a valid e-mail address
url
A field is a url
integer
A field is an integer value or matches an integer range*
decimal
A field must be a decimal number or matches a decimal range*
number
A field is any number or matches a number range*
regExp
Matches against a regular expression
creditCard
A field is a valid credit card**
contains
, doesntContain
A field (doesn't) contain text (case insensitive)
containsExactly
, doesntContainExactly
A field (doesn't) contain text (case sensitive)
is
, not
A field is (not) a value (case insensitive)
isExactly
, notExactly
A field is (not) a value (case sensitive)
minLength
, exactLength
, maxLength
A field is at least/exactly/at most a set length
match
, different
A field should (not) match the value of another validation field. Use the field ID as the value
minCount
, exactCount
, maxCount
A multiple select field contains at least/exactly/at most a set number of selections
*
For ranges, include the parameter value = "x..y"
where x
is the minimum value and y
is the maximum value.
Leave either side blank to not have a lower/upper limit
**
Include comma separated string of card providers if required e.g. value = "visa,mastercard"
A structured list of the field_rules
that can be recognised by form_validation
.
https://fomantic-ui.com/behaviors/form.html
1 2 3 4 5 6 7 8 9 10 | # E-mail validations
field_validation("email", field_rule("email"))
# Password validation
field_validation(
"password",
field_rule("empty"),
field_rule("minLength", value = 8),
field_rule("regExp", "Must contain at least one special character", "\\W")
)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.