| 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
|
min
and
max
options is required.
// You might need to change the importing path
import
stringLength
from
'formvalidation/dist/es6/validators/stringLength'
;
const
result
=
stringLength
(
)
.
validate
(
{
value
:
...
,
options
:
{
'case'
:
...
,
message
:
...
,
}
,
}
)
;
/*
result is an object of
{
valid: true or false,
message: The error message
}
*/
maxlength
or
minlength
attribute.
// You might need to change the importing path
import
stringLength
from
'formvalidation/dist/es6/validators/stringLength'
;
const
res1
=
stringLength
(
)
.
validate
(
{
value
:
'123456'
,
options
:
{
max
:
10
,
message
:
'The input has to be less than 11 characters'
,
}
,
}
)
;
// res1.valid === true
const
res2
=
stringLength
(
)
.
validate
(
{
value
:
'1234567890♥'
,
options
:
{
min
:
5
,
max
:
10
,
message
:
'The input has to be between 5 and 10 characters long'
,
}
,
}
)
;
// res2.valid === false
max
and
min
options aren't passed to the placeholder message