Class: RegExpValidator

Oracle® JavaScript Extension Toolkit (JET)
1.1.2

E65298-01

QuickNav

oj. RegExpValidator

Version:
  • 1.1.2
Since:
  • 0.6

Constructor

new RegExpValidator(options)

Constructs a RegExpValidator that ensures the value matches the provided pattern
Parameters:
Name Type Description
options Object an object literal used to provide the pattern, an optional hint and error message.
Properties
Name Type Argument Description
pattern RegExp <optional>
a regexp pattern that the validator matches a value against.

Example:
'\\d{10}'

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.

Tokens:
{pattern} - the pattern to enforce

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

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.

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

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.

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"

Source:

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.
Source:
Returns:
a hint message or null if no hint is available in the options
Type
String | null

Init(options)

Initializes validator instance with the set options
Parameters:
Name Type Description
options Object
Source:

validate(value) → {boolean}

Validates value for matches using the regular expression provided by the pattern. This method does not raise error when value is empty string or null, then this method returns.
Parameters:
Name Type Description
value string | number that is being validated
Source:
Throws:
when there is no match
Type
Error
Returns:
true if validation was successful
Type
boolean