mikeerickson / validatorjs

A data validation library in JavaScript for the browser and Node.js, inspired by Laravel's Validator.
https://www.npmjs.com/package/validatorjs
MIT License
1.77k stars 279 forks source link

Add custom validation rules to a single Validator instance #98

Open renarsvilnis opened 8 years ago

renarsvilnis commented 8 years ago

Feature request:

Allow to use register and registerAsync on a new Validator instance to register custom rules that are only scoped to the instance.

My proposal is to add rules property to the options object in the constructor (explained in more detailed #97). Where rules would be an object where the keys are the rule names and the their values would be functions.

~~But that would require changes on how custom validation functions are registered. As of now you must pass a errorMessage on calling register function, but for the registerAsync the errorMessage is passed to the pass(false, errorMessage). There is a need normalizing the arguments for both register and registerAsync.~~ Looked at source-code, looks like README.md is not update-to-date.

What are you thoughts about this? I can make a PR if interested.

goshoo commented 7 years ago

I also would like this feature to be implemented.