Class: NumberRangeValidator

Oracle® JavaScript Extension Toolkit (JET)
7.1.0

F18183-01

Signature:

class NumberRangeValidator implements Validator<string|number>

QuickNav


NumberRangeValidator

Version:
  • 7.1.0
Since:
  • 0.7
Module:
  • ojvalidation-number

Module usage

See JET Module Loading for an overview of module usage within JET.

Javascript Import Format
define(['ojs/ojvalidation-number'], function(validationNumber) {
 // Application should call API on validationNumber.NumberRangeValidator 
})
Typescript Import Format
//To import this class, use the format below.
import {NumberRangeValidator} from "ojs/ojvalidation-number";

JET In Typescript

A detailed description of working with JET elements and classes in your typescript project can be found at: JET Typescript Usage.

See:

Constructor

new NumberRangeValidator(options)

Constructs a NumberRangeValidator that ensures the value provided is within a given range. In most use cases you will use the ValidatorFactory to get an instance of a NumberRangeValidator instead of using the constructor.
Parameters:
Name Type Argument Description
options oj.NumberRangeValidator.ValidatorOptions <optional>
an object literal used to provide the following properties
See:

Methods

getHint() → {string|null}

Returns:
a hint message or null if no hint is available in the options. A hint message may be like "Enter a value between {min} and {max}" or "Enter a number greater than or equal to {min}"
Type
string | null

validate(value) → {void}

Validates the minimum + maximum conditions
Parameters:
Name Type Description
value string | number that is being validated
Throws:
when value is out of range
Type
Error
Returns:
original if validation was successful
Type
void

Type Definitions

ValidatorOptions

Properties:
Name Type Argument Description
converter oj.NumberConverter <optional>
an instance implementation of oj.NumberConverter. It is used to format the value in error message. It is optional for the validator that a converter is passed in.
min number <optional>
the minimum number value of the entered value.
max number <optional>
the maximum number value of the entered value.
hint Object <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
max string <optional>
a hint used to indicate the allowed maximum. When not present, the default hint is the resource defined with the key oj-validator.range.number.hint.max.

Tokens:
{max} - the maximum

Usage:
Enter a number less than or equal to {max}

min string <optional>
a hint used to indicate the allowed minimum. When not present, the default hint is the resource defined with the key oj-validator.range.number.hint.min.

Tokens:
{min} the minimum

Usage:
Enter a number greater than or equal to {min}

inRange string <optional>
a hint used to indicate the allowed range. When not present, the default hint is the resource defined with the key oj-validator.range.number.hint.inRange.

Tokens:
{min} the minimum
{max} the maximum

Usage:
Enter a number between {min} and {max}

exact string <optional>
a hint used to indicate the allowed value. This is used when min and max are non-null and are equal to each other. When not present, the default hint is the resource defined with the key oj-validator.range.number.hint.exact.

Tokens:
{num} the number allowed
Usage:
Enter the number {num}

messageDetail Object <optional>
an optional object literal of custom error messages to be used.

The messageDetail strings (e.g., messageDetail.rangeUnderflow) 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
rangeUnderflow string <optional>
the detail error message to be used when input value is less than the set minimum value. When not present, the default detail message is the resource defined with the key oj-validator.range.number.messageDetail.rangeUnderflow.

Tokens:
{value} - value entered by the user
{min} - the minimum allowed value

Usage:
The number must be greater than or equal to {min}.

rangeOverflow string <optional>
the detail error message to be used when input value exceeds the maximum value set. When not present, the default detail message is the resource defined with the key oj-validator.range.number.messageDetail.rangeOverflow.

Tokens:
{value} - value entered by the user
{max} - the maximum allowed value

Usage:
The number must be less than or equal to {max}.

exact string <optional>
the detail error message to be used when the input value is not between min and max when min and max are both non-null and equal. When not present, the default detail message is the resource defined with the key oj-validator.range.number.messageDetail.exact.

Tokens:
{num} - the allowed value

Usage:
The number must be {num}.

messageSummary Object <optional>
optional object literal of custom error summary message to be used.
Properties
Name Type Argument Description
rangeUnderflow string <optional>
the summary of the 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.range.number.messageSummary.rangeUnderflow.
rangeOverflow string <optional>
the summary of the error message when input value exceeds the maximum value set. When not present, the default message summary is the resource defined with the key oj-validator.range.number.messageSummary.rangeOverflow.
Since:
  • 3.0.0