Final Class: RegExpValidator

Oracle® JavaScript Extension Toolkit (JET)
17.1.0

G12196-01

Since:
  • 0.6.0
Module:
  • ojvalidator-regexp

QuickNav

Description

Constructs a RegExpValidator that ensures the value matches the provided pattern.


Usage

Signature:

final class RegExpValidator implements Validator<string|number>

Typescript Import Format
//This class is exported directly as module. To import it
import RegExpValidator= require("ojs/ojvalidator-regexp");

For additional information visit:


Final classes in JET

Classes in JET are generally final and do not support subclassing. At the moment, final is not enforced. However, this will likely change in an upcoming JET release.


See:
  • oj.AsyncRegExpValidator

Constructor

new RegExpValidator(options)

Constructs a RegExpValidator that ensures the value matches the provided pattern.
Parameters:
Name Type Argument Description
options oj.RegExpValidator.ValidatorOptions <optional>
an object literal used to provide the pattern, an optional hint and error message.
See:
  • oj.AsyncRegExpValidator

Methods

getHint : {string|null}

A message to be used as hint, when giving a hint on the expected pattern. 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 value for matches using the regular expression provided by the pattern. This method does not raise an error when value is the empty string or null; the method returns true indicating that the validation was successful. If the application wants the empty string to fail validation, then the application should chain in the required validator (e.g., set required on the input).
Parameters:
Name Type Description
value string | number that is being validated
Throws:
when there is no match
Type
Error
Returns:
Type
void

Type Definitions

ValidatorOptions

Properties:
Name Type Argument Description
hint string <optional>
an optional hint text. There is no default hint provided by the validator. It is generally not recommended to show the actual pattern in the hint as it might be confusing to end-user, but if you do, you can use the {pattern} token.

The hint string is 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 ('$').

Tokens:
{pattern} - the pattern to enforce

Example:
"value must meet this pattern {pattern}"

label string <optional>
an optional label text used when the {label} token is passed into messageSummary or messageDetail.
messageDetail string <optional>
a custom error message to be used for creating detail part of message, when the users input does not match the specified pattern. When not present, the default detail message is the resource defined with the key oj-validator.regExp.detail.

The messageDetail string is 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 ('$').

Tokens:
{label} - label text of the component for which this message applies.
{pattern} the 'pattern' that the value should match
{value} value entered by the user

Examples:
"The value {value} must contain at least 3 alphanumeric characters"

messageSummary string <optional>
a custom error message summarizing the error when the users input does not match the specified pattern. When not present, the default summary is the resource defined with the key oj-validator.regExp.summary. It is generally not recommended to show the actual pattern in the message as it might be confusing to end-user.

The messageSummary string is 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 ('$').

Tokens:

{label} - label of the component for which this message applies. The label may not always be available depending on the usage of the validator.
{pattern} - the pattern the value should match
{value} - value entered by user

Examples:
"'{label}' Format Incorrect" // translating to 'Phone Number' Format Incorrect

pattern string <optional>
a regexp pattern that the validator matches a value against.

Example:
'\\d{10}'