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>.

  inclusive = c(TRUE, TRUE),
  message_fmt = "Must be between {left} and {right}.",
  allow_na = FALSE,
  allow_nan = FALSE


left, right

The left and right boundary values. Inclusively for each of the boundaries is set with the inclusive argument; the defaults are set for inclusive bounds.


A two-element logical vector that indicates whether the left and right bounds, respectively, should be inclusive. Both bounds are by default are inclusive, using c(TRUE, TRUE).


The validation error message to use if a value fails to match the rule. The message can be customized by using the "{left}" and "{right}" string parameters, which allows for the insertion of the left and right values. While the default message uses both of these string parameters, they are not required in a user-defined message_fmt string.


If FALSE (the default for both options), then any NA or NaN element will cause validation to fail.


If FALSE (the default for both options), then any NA or NaN element will cause validation to fail.


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()


## Only run examples in interactive R sessions
if (interactive()) {


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

shinyApp(ui, server)