Validation


A brief description about our validation
  • Validation rules are defined within schema files.
  • Validation using validator library for covering commonly used validators.
  • It will throw an exception with the error message whenever validation fails.
  • By default validation happens when insert method is invoked or you can use validate method to validate manually.
  • You can implement custom validators.

Syntax


  • func : A predefined validator function or a custom validation function which returns Boolean and it can be a async function as well.
  • args : Additional argument to pass in corresponding validator function.
  • msg : Error message corresponding to each validator. You can use {VALUE} within the string literal to get the value which will get replaced with the value while throwing the error.

Examples

Validation Example 1 :


Validation Example 2 :


Built-in Validators

For more about predefined validation functions refer following link : https://github.com/validatorjs/validator.js#validators


Custom Validator

You can write custom validate function in which you can get first argument as column value and remaining would be the argument specified in the args array. Custom validator function should return a Boolean and the function can be a async function as well.

Custom Validator Example :

Subscribe to Our Newsletter

Let us stretch your imagination

Download App