validatorjs icon indicating copy to clipboard operation
validatorjs copied to clipboard

Ability to register a rule per validator instance

Open foxhound87 opened this issue 2 years ago • 0 comments

Hello, right now to register a new rule you have to call Validator.register() and the rule is available in a new Validator instance. But I have an issue when registering multiple rule functions with same key/name, the functions takes in input the arguments of the last registered rule.

Would be nice to have the ability to create specific rules for each validator instance. Something like this:

const validator = new Validator(); // empty constructor 
validator.register(name, callbackFn, errorMessage);

const validation = validator.validate(data, rules);
validation.passes(); // true
validation.fails(); // false

Related Issue: https://github.com/foxhound87/mobx-react-form/issues/579

foxhound87 avatar Apr 04 '23 12:04 foxhound87