stringLength validator

Validate the length of a string

Options

Using with form field

* presents a required option. The HTML attributes are used to set the validator options via the Declarative plugin

Name HTML attribute Type Description
max* data-fv-string-length___max or maxlength Number The maximum length
message data-fv-string-length___message String The error message
min* data-fv-string-length___min or minlength Number The minimum length
utf8Bytes data-fv-string-length___utf8-bytes Boolean Evaluate string length in UTF-8 bytes. Default to false
trim data-fv-string-length___trim Boolean Indicate the length will be calculated after trimming the value or not. Default to false

At least one of min and max options is required.

Using with ES6 module

Basic Example

In the following form, the Full name and Bio fields must be less than 50 and 200 characters respectively.

HTML5 Example

When the Declarative plugin is used, the stringLength validator will be turned on automatically if the input uses HTML 5 maxlength or minlength attribute.

ES6 Module Example

The following snippet shows how to use the stringLength validator with ES6 module:

Related validators

The following validators might be useful to you.