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 280 forks source link

Accept only keys defined in rule object #448

Open bytemerger opened 2 years ago

bytemerger commented 2 years ago

I am using the version 3.22.1

Could it be possible to have a feature where the validator can return an error if data key with that is not defined in the rule is passed for instance

const validator = new Validator(req.body, {
        name: 'string',
        body: 'string',
    });

The above should return an error if req.body contains more object keys than defined in the rule

A solution could be to add a third instance parameter to new Validator(data,rule,strict) strict would either be true or false. This would mean whether the validator should follow the rule strictly not allowing additional keys or not.

eyan commented 2 years ago

+1 for this feature request!