Questions tagged [express-validator]

An express.js middleware library for validation and sanitization.

express-validator is an express.js middleware library for HTTP requests validation and sanitization.

The built-in validators and sanitizers are provided by the JavaScript library validator, but support for extending the middleware with custom validators and/or sanitizers is also available.

458 questions
38
votes
5 answers

Validate array of objects in express validator

I am using express validator to validate my fields. But now i have array of 2 or 3 objects, which contains the "userId" and "Hours" fields like below. [ { user_id:1, hours:8 }, { user_id:2, hours:7 } ] Now i need to…
user10298495
14
votes
4 answers

How to implement validation in a separate file using express-validator

I am trying to use express-validator to validate the req.body before sending a post request to insert data to postgres. I have a route file, controller file and I want to carryout validation in a file called validate.js. Meanwhile, I have installed…
Micah Bala
  • 141
  • 1
  • 1
  • 5
13
votes
5 answers

Validate input is within a numeric range, possibly a float, using express-validator

I'm trying to validate if the input is an integer or a float within a certain range using express-validator. I've tried: check( 'rating', 'Rating must be a number between 0 and 5' ).isNumeric({ min: 0, max: 5 }), but the min and max…
Alexander
  • 161
  • 1
  • 1
  • 4
11
votes
1 answer

Use express-validator as a middleware with websockets

I used Sails.js + Passport.js authentication through websockets to bind passport.js methods for requests through websockets (using sockets.io) , but how should i add express-validator methods to ensure that all requests have methods from it
kobe24
  • 190
  • 1
  • 5
  • 16
10
votes
4 answers

How to validate request body in Node.js, Express - is it possible without using a library?

I have the code (below) and one developer said to me that I had to validate my request: router.post('/dashboard', passport.authenticate('jwt', { session: false }), (req, res) => { try { let newPost = new Post({ category:…
Tatyana Molchanova
  • 1,305
  • 5
  • 12
  • 23
10
votes
2 answers

Express-validator how to make a field required only when another field is present

express-validator, how do I make a field required only when another field exists? const validateUpdateStore = () => { return [ body('logo').optional().isURL().withMessage('invalid url'), body('email') .optional() .isEmail() …
Damiisdandy
  • 357
  • 3
  • 12
10
votes
1 answer

How do I exclude additional properties using express-validator?

I am using express-validator in my express app, and I am attempting to prevent additional fields being specified on POST requests. This is because I am passing the value of req.body to my ORM to insert into the database, and I want to avoid having…
coderdude123
  • 311
  • 2
  • 7
10
votes
3 answers

express-validator: how to check queries

With express-validator how can we check the query for a request? In the documentation there is an example to check body: const { check, validationResult } = require('express-validator/check'); app.post('/user', [ // username must be an email …
Valeri
  • 1,072
  • 5
  • 14
  • 31
10
votes
2 answers

No errors with express-validator isEmpty

I am using express-validator 5.2.0 in a expressjs app. I implemented the validaiton on a form data. But it does not capture the errors and gives empty errors object. When validation runs it shows the "no error" when I submit the empty form. It…
Arun kumar
  • 1,041
  • 5
  • 20
  • 39
10
votes
3 answers

Validation In Express-Validator

I am using express-validator for validation. I am using mongoose for database, it also has validation built in. I want to know which one should I use? I also want to know if the validation in express-validator is parallel. Take this code for…
9
votes
2 answers

Express validation, custom async checking

So, I have done a pretty good amount of research on this and I am having some issues. router.post('/register', async (req, res) => { const newUser = await usersDb(); // Define the user const email = req.body.email; const username =…
William
  • 1,175
  • 2
  • 17
  • 32
9
votes
3 answers

How to validate the length of character is equals to 5 using express-validator?

I am planning to make partnerid field character length as 5 which means user will get error message if he enters less than 5 character or more than 5 characters which will include alpha-numeric character. How can we do it using express-validator? I…
Bibek
  • 943
  • 1
  • 12
  • 22
9
votes
1 answer

Access request body in check function of express-validator v4

I just started using express.js with express-validator to validate some input data and I have problems accessing the request body in the new check API that was introduced in version 4.0.0. In older versions, you simply added express-validator as…
Martin Reiche
  • 1,642
  • 1
  • 16
  • 27
8
votes
2 answers

express-validator returns validation errors twice

I want to validate the request object using Express-Validator. Let's assume I have two routes, a GET /users/:id (fetchUserById) and POST /users (createUser) route this.router =…
Question3r
  • 2,166
  • 19
  • 100
  • 200
8
votes
3 answers

Validating req.params with express validator

I want the user to be able to write a specific account number in the endpoint, been trying to validate the endpoint param if it exists in my database. I couldn't get it to work, please what am I doing wrong? My validation const validateReq:…
Pelumi
  • 413
  • 2
  • 5
  • 13
1
2 3
30 31