Validators are used on class properties to test that the value of property conforms to a specification as defined by the validator. Multiple validators can exist on a given class property. All validators must be satisfied on a class property in order for the overall validation on that property to succeed.
When classes are extended or augmented, it is possible to add validators to a property by including the property name in the extended or augmented class. It is not possible to reduce the validation on a class property.
Validators can also be used at the class level. These are useful for validating whole class semantics or multiple properties in a single validator.
Validators can be defined external to the class, making them available to all classes, or they can be defined within the class itself. This documentation details external validators only. See Classes to learn more about inline validation.
Validation of classes and class properties occurs in 3 phases - EARLY, MID and LATE. More on this can be found in Validation.
[com.appirator.core.]reflect.Validator
extends [com.appirator.core.]reflect.ModuleScriptable
extends [com.appirator.core.]reflect.ModuleNamed
extends [com.appirator.core.]Object
parent [com.appirator.core.]reflect.Module
phase optional
The validation phase, one of EARLY, MID or LATE. The default phase is EARLY.
name optional (when using Git sync)
The name of the validator in its associated module. This is taken from the file name by default if the event handler is being imported as a file. It can be prefixed with the path name of the file when imported as a file where the path segments are separated with a dot. Similarly, if created object over a REST interface dot notation is permitted. This must be unique within the module.
script
The script to be run. This should be in the same language as the associated module.
[Pattern.val.yaml]
name: Pattern
script: >
function () {
if (value === null) {
return true;
}
var pattern = params.pattern;
if (pattern instanceof String) {
pattern = new RegExp(pattern);
}
return pattern instanceof RegExp && pattern.test(value);
}