- See:
-
- oj.AsyncLengthValidator
Constructor
new LengthValidator(options)
By default this uses Javascript's String length property
which counts a UTF-16 surrogate pair as length === 2.
If you need to count surrogate pairs as length === 1, then set the
countBy option to "codePoint"
or use
oj.LengthValidator.defaults.countBy = "codePoint";
to set the page-wide default.
You can customize the default messages of all validators including this one using the messageDetail and messageSummary options.
Parameters:
| Name | Type | Argument | Description |
|---|---|---|---|
options |
oj.LengthValidator.ValidatorOptions |
<optional> |
an object literal used to provide:
|
- See:
-
- oj.AsyncLengthValidator
Fields
-
(static) defaults :object
-
The set of attribute/value pairs that serve as default values when new LengthValidator objects are created.
LengthValidator's
countByoption may be changed for the entire application after the 'ojs/ojvalidator-length' module is loaded (each form control module includes the 'ojs/ojvalidator-length' module). If theoptions.countByis specifically set, it will take precedence over this default.For example:
oj.LengthValidator.defaults.countBy = 'codePoint';- Since:
- 2.1.0
Properties:
Name Type Description countBystring count the length by "codeUnit"or"codePoint". Defaults to"codeUnit".
Methods
-
getHint : {string|null}
-
A message to be used as hint, when giving a hint about the expected length. There is no default hint for this property.
Returns:
a hint message or null if no hint is available in the options- Type
- string | null
-
validate(value) : {void}
-
Validates the length of value is greater than minimum and/or less than maximum.
Parameters:
Name Type Description valuestring | number that is being validated Throws:
when the length is out of range.- Type
- Error
Returns:
- Type
- void
Type Definitions
-
ValidatorOptions
-
Properties:
Name Type Argument Description countBy'codeUnit' | 'codePoint' <optional>
A string that specifies how to count the length. Valid values are "codeUnit"and"codePoint". Defaults tooj.LengthValidator.defaults.countBywhich defaults to"codeUnit".
"codeUnit"uses javascript's length function which counts the number of UTF-16 code units. Here a Unicode surrogate pair has a length of two.
"codePoint"counts the number of Unicode code points. Here a Unicode surrogate pair has a length of one.
minnumber <optional>
a number 0 or greater that is the minimum length of the value. maxnumber <optional>
a number 1 or greater that is the maximum length of the value. hintObject <optional>
an optional object literal of hints to be used. The hint strings (e.g., hint.min) are passed as the 'pattern' parameter to oj.Translations.html#applyParameters. As stated in that documentation, if you are using a reserved character, you need to escape it with a dollar character ('$').
Properties
Name Type Argument Description maxstring <optional>
a hint message to be used to indicate the allowed maximum. When not present, the default hint is the resource defined with the key oj-validator.length.hint.max.Tokens:
{max} - the maximumUsage:
Enter {max} or fewer charactersminstring <optional>
a hint message to be used to indicate the allowed minimum. When not present, the default hint is the resource defined with the key oj-validator.length.hint.min.Tokens:
{min} the minimumUsage:
Enter {min} or more charactersinRangestring <optional>
a hint message to be used to indicate the allowed range. When not present, the default hint is the resource defined with the key oj-validator.length.hint.inRange.Tokens:
{min} the minimum{max} - the maximum
Usage:
Enter between {min} and {max} charactersexactstring <optional>
a hint message to be used, to indicate the exact length. When not present, the default hint is the resource defined with the key oj-validator.length.hint.exact.Tokens:
{length} the lengthUsage:
Enter {length} charactersmessageDetailObject <optional>
an optional object literal of custom error messages to be used. The messageDetail strings (e.g., messageDetail.tooLong) are passed as the 'pattern' parameter to oj.Translations.html#applyParameters. As stated in that documentation, if you are using a reserved character, you need to escape it with a dollar character ('$').
Properties
Name Type Argument Description tooLongstring <optional>
the detail error message to be used as the error message, when the length of the input value exceeds the maximum value set. When not present, the default detail message is the resource defined with the key oj-validator.length.messageDetail.tooLong.Tokens:
{value} - value entered by the user
{max} - the maximum allowed valueUsage:
The {value} has too many characters. Enter {max} or fewer characters, not more.tooShortstring <optional>
the detail error message to be used as the error message, when the length of the input value is less the minimum value set. When not present, the default detail message is the resource defined with the key oj-validator.length.messageDetail.tooShort.Tokens:
{value} - value entered by the user
{min} - the minimum allowed valueUsage:
The {value} has too few characters. Enter {min} or more characters, not less.messageSummaryObject <optional>
optional object literal of custom error summary message to be used. The messageSummary strings (e.g., messageSummary.tooLong) are passed as the 'pattern' parameter to oj.Translations.html#applyParameters. As stated in that documentation, if you are using a reserved character, you need to escape it with a dollar character ('$').
Properties
Name Type Argument Description tooLongstring <optional>
the message to be used as the summary error message, when the length of the input value exceeds the maximum value set. When not present, the default message summary is the resource defined with the key oj-validator.length.messageSummary.tooLong.tooShortstring <optional>
the message to be used as the summary error message, when input value is less than the set minimum value. When not present, the default message summary is the resource defined with the key oj-validator.length.messageSummary.tooShort.