Class: RegExpValidator

Oracle® JavaScript Extension Toolkit (JET)
3.2.0

E87541-01

QuickNav

oj. RegExpValidator

Version:
  • 3.2.0
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, 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}"

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

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"

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 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
Source:
Throws:
when there is no match
Type
Error
Returns:
true if validation was successful
Type
boolean