checkSchema - custom validator and exists errorMessage
See original GitHub issueHi!
I’m trying to use Schema Validation with 5.0.0.
custom
validator throw validation errorvalidatorCfg.validator is not a function
- For
exists
paramerrorMessage
ignored
checkSchema({
title: {
in: ['body'],
exists: {
errorMessage: 'title is required', // <- doesn't work
},
custom(value) { // <- doesn't work
console.log(value);
return true;
}
},
password: {
isLength: {
errorMessage: 'Password should be at least 7 chars long', // <- works
},
},
});
customValidators
param and all in this doc section https://github.com/ctavan/express-validator#legacy-api are deprecated…
What am I doing wrong?
Issue Analytics
- State:
- Created 6 years ago
- Comments:17 (8 by maintainers)
Top Results From Across the Web
express-validator checkSchema not raise errors - Stack Overflow
I took a look at documentation and I saw that: app.post( '/user', body('username').isEmail(), body('password').isLength({ min: 5 }), (req, ...
Read more >Schema Validation - express-validator
Schemas are a special, object-based way of defining validations or sanitizations on requests. At the root-level, you specify field paths as keys, and...
Read more >express-validator.checkSchema JavaScript and Node.js code ...
Best JavaScript code snippets using express-validator. ... errorMessage: lang.t('errors.password.exists'), custom: { options: (password, { req }) => User.
Read more >Form Data Validation in Node.js with express-validator
Let's now switch to the registration endpoint and cover tasks like custom validation rules, error messages, schema validation and ...
Read more >How to perform custom validation in your Express.js app (Part-2)
Custom validators return Promises to show an async validation or throw any value/reject a promise to use a custom error message.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hm, the
exists
one is strange, by “doesn’t work” do you mean the error message is stillInvalid value
? It shouldn’t be, so there might be something else wrong with your setup.The
custom
one should be specified by passingoptions
. I will add an example to help clear future questions about it.This is a very minimal app with both validators working:
Hi @prettymuchbryce, it’s out of the plans for the check APIs to have any interactions with the legacy ones (the
expressValidator
middleware you used), as they are gonna be phased out at some point. The less state we store in the request, the better.What I would like to do instead is something like
validatorResult.withDefaults(options)
: a factory for the check API that you can inject custom defaults, like validators:For now, what you can do is move these validators or schemas (or whatever you like) into separate files, and import them in your schemas.