sv_between {shinyvalidate} | R Documentation |
Validate that a field is a number bounded by minimum and maximum values
Description
The sv_between()
function validates that a field has values between left
and right boundary values. Both bounds are inclusive by default, but both can
be set as either inclusive or exclusive with the inclusive
argument. In its
default mode, the validation check will effectively be of the form <left> <= <field> <= <right>
.
Usage
sv_between(
left,
right,
inclusive = c(TRUE, TRUE),
message_fmt = "Must be between {left} and {right}.",
allow_na = FALSE,
allow_nan = FALSE
)
Arguments
left , right |
The left and right boundary values. Inclusively for each of
the boundaries is set with the |
inclusive |
A two-element logical vector that indicates whether the
|
message_fmt |
The validation error message to use if a value fails to
match the rule. The message can be customized by using the |
allow_na , allow_nan |
If |
Value
A function suitable for use as an
InputValidator$add_rule()
rule.
See Also
The sv_in_set()
function, which tests whether a field values are
part of a specified set.
Other rule functions:
compose_rules()
,
sv_email()
,
sv_equal()
,
sv_gte()
,
sv_gt()
,
sv_in_set()
,
sv_integer()
,
sv_lte()
,
sv_lt()
,
sv_not_equal()
,
sv_numeric()
,
sv_optional()
,
sv_regex()
,
sv_required()
,
sv_url()
Examples
## Only run examples in interactive R sessions
if (interactive()) {
library(shiny)
library(shinyvalidate)
ui <- fluidPage(
textInput("count", "Count")
)
server <- function(input, output, session) {
# Validation rules are set in the server, start by
# making a new instance of an `InputValidator()`
iv <- InputValidator$new()
# Basic usage: `sv_between()` requires `left` and
# `right` boundary values; a message will be
# displayed if the validation of `input$count` fails
iv$add_rule("count", sv_between(10, 100))
# Finally, `enable()` the validation rules
iv$enable()
}
shinyApp(ui, server)
}