Class: ValidatorFactory

Oracle® JavaScript Extension Toolkit (JET)
4.2.0

E91398-01

QuickNav

Fields

oj. ValidatorFactory

Version:
  • 4.2.0

Constructor

<abstract> new ValidatorFactory()

Contract for a ValidatorFactory that provides a factory method to create a validator instance for the requested type. JET provides several factory implementations that implement this contract - for example dateRestriction, dateTimeRange, numberRange, length, required, regexp. Customers can register custom validator factories for the supported types or create and register factories for new types altogether.
See:

Fields

<static> VALIDATOR_TYPE_DATERESTRICTION :string

Default type for a factory used to create date restriction validators. This type is passed to the Validation.validatorFactory method to retrieve the dateRestriction validator factory of type oj.DateRestrictionValidatorFactory.
Example

Create a JET dateRestriction validator

var validatorFactory = 
oj.Validation.validatorFactory(oj.ValidatorFactory.VALIDATOR_TYPE_DATERESTRICTION);
var options = {dayFormatter : self.aprilFoolsFormatter, // your own formatter code
message : {messageDayMetaData : 'You can\'t fool me! Try a different date.'}};
var validator = validatorFactory.createValidator(options);

<static> VALIDATOR_TYPE_DATETIMERANGE :string

Default type for a factory used to create required validators. This type is passed to the Validation.validatorFactory method to retrieve the dateTimeRange validator factory of type oj.DateTimeRangeValidatorFactory.
Example

Create a JET datetime validator

var validator = 
oj.Validation.validatorFactory(oj.ValidatorFactory.VALIDATOR_TYPE_DATETIMERANGE)
.createValidator({{max: oj.IntlConverterUtils.dateToLocalIso(new Date()),
min: oj.IntlConverterUtils.dateToLocalIso(new Date(2000, 00, 01)),
hint: {'inRange': 'Enter a date that falls in the current millennium.'}}); 

<static> VALIDATOR_TYPE_LENGTH :string

Default type for a factory used to create length validators. This type is passed to the Validation.validatorFactory method to retrieve the length validator factory of type oj.LengthValidatorFactory.
Example

Create a JET length validator

var validatorFactory = 
oj.Validation.validatorFactory(oj.ValidatorFactory.VALIDATOR_TYPE_LENGTH); 
var options = {min: 5, max: 10};
var validator = validatorFactory.createValidator(options);

<static> VALIDATOR_TYPE_NUMBERRANGE :string

Default type for a factory used to create numberRange validators. This type is passed to the Validation.validatorFactory method to retrieve the numberRange validator factory of type oj.NumberRangeValidatorFactory.
Example

Create a JET numberrange validator

var validatorFactory = 
oj.Validation.validatorFactory(oj.ValidatorFactory.VALIDATOR_TYPE_NUMBERRANGE); 
var options = {min: 10000.05, max: 25000.95, 
hint: {inRange: 'Enter a value between {min} and {max}.'}};
var validator = validatorFactory.createValidator(options);

<static> VALIDATOR_TYPE_REGEXP :string

Default type for a factory used to create regExp validators. This type is passed to the Validation.validatorFactory method to retrieve the regExp validator factory of type oj.RegExpValidatorFactory.
Example

Create a JET regexp validator

var validatorFactory = 
oj.Validation.validatorFactory(oj.ValidatorFactory.VALIDATOR_TYPE_REGEXP);
var options =  
{pattern: '[a-zA-Z0-9]{3,}', 
hint: 'enter at least 3 letters or numbers.',
messageDetail: 'You must enter at least 3 letters or numbers.'}
var validator = validatorFactory.createValidator(options);

<static> VALIDATOR_TYPE_REQUIRED :string

Default type for a factory used to create required validators. This type is passed to the Validation.validatorFactory method to retrieve the required validator factory of type oj.RequiredValidatorFactory.
Example

Create a JET required validator

var rvf = oj.Validation.validatorFactory(oj.ValidatorFactory.VALIDATOR_TYPE_REQUIRED); 
var options = {'hint' : 'a value is required for this field'};
var requiredValidator = rvf.createValidator(options);

Methods

<static> createValidator(options) → {Object}

Creates an immutable validator instance of the type the factory implements. For the specific options parameters, see the Validator jsdoc for the validator you are creating, e.g., oj.RequiredValidator if you are creating a required validator.
Parameters:
Name Type Description
options Object | null an object literal containing properties required by the validator for its initialization. The properties provided in the options is implementation specific.
See:
Throws:
if an unrecognized type was provided
Type
TypeError
Returns:
a validator instance.
Type
Object
Example

create an instance of the required validator using the factory

var rvf = oj.Validation.validatorFactory(oj.ValidatorFactory.VALIDATOR_TYPE_REQUIRED); 
var options = {'hint' : 'a value is required for this field'};
var requiredValidator = rvf.createValidator(options);