Custom Validators

You can build also your own validators by implementing our interface cbvalidaton.models.validators.IValidator :

/**
* Will check if an incoming value validates
* @validationResult.hint The result object of the validation
* @target.hint The target object to validate on
* @field.hint The field on the target object to validate on
* @targetValue.hint The target value to validate
*/
boolean function validate(required cbvalidation.models.result.IValidationResult validationResult, required any target, required string field, any targetValue, any validationData);

/**
* Get the name of the validator
*/
string function getName();

The arguments received are:

  • validationResults : The validation result object

  • field : The field or property in the object that is in validation

  • targetValue : The value to test

Here is a sample validator:

Last updated

Was this helpful?