Using a Hook to Extend the Validator

Learn how to use a hook to extend the validator by adding a custom rule.

We'll cover the following

According to the Adonis documentation, hooks can be used to execute code at a specific time in the application lifecycle. We register hooks inside start/hooks.js.

Extending the validator

IndicativeIndicative is a data validation library. does not cover all the validation rules, so we sometimes have to add custom rules to the validator. Suppose we want to ensure that the username (provided through the form) does not contain the strings “aaa” and “bbb”. To extend the validator, we will implement our validation function in start/hooks.js.

Get hands-on with 1400+ tech skills courses.