field_validation {fomantic.plus}R Documentation

Field Validation for Fomantic UI

Description

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.

Usage

field_validation(id, ..., extra_params = NULL)

field_rule(rule, prompt = NULL, value = NULL)

Arguments

id

HTML id of the field to be validated

...

A series of field_rules that will be applied to the field

extra_params

A named list of extra parameters that can be added to the field validation. For example optional = TRUE means the field will only be checked if non-empty

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 NULL if want to use default text.

value

Certain fields require a value to check validation. Check Details if the rule requires a value.

Details

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"

Value

A structured list of the field_rules that can be recognised by form_validation.

References

https://fomantic-ui.com/behaviors/form.html

See Also

form_validation

Examples

# 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")
)


[Package fomantic.plus version 0.1.0 Index]