Questions tagged [express-validator]

An express.js middleware library for validation and sanitization.

Filter by
Sorted by
Tagged with
0 votes
0 answers
12 views

express-validator issues with checkSchema

I'm new to express in general but I feel like my issue is unrelated. Attached below is my route with the checkSchema call to validate different fields. The intended functionality is to only validate ...
Kaitlyn Rosen's user avatar
0 votes
1 answer
90 views

Custom server bodyParser and nextauth conflicting

I have my ...nextauth as guided in documentation like so: I have a custom server as so: app.prepare().then(() => { const server = express(); server.use(cors()) server.use('/...
D. Rattansingh's user avatar
0 votes
1 answer
31 views

Allowing empty strings in Validator.js

I am trying to combine Zod and Validator.js to validate form data. I want to allow empty strings "" for optional fields. I think this snippet should work but it does NOT and I cannot figure ...
Aslan's user avatar
  • 85
0 votes
2 answers
42 views

Express validator always returning error even when valid

I am using postman to send a post request with some data in the body, but express validator is always returning the error array. Here is the index.js code: import express from "express"; ...
Na N's user avatar
  • 5
0 votes
0 answers
11 views

Express Validator unexpected token error on EC2 instance but works fine on local machine

terminal errors I'm trying to host an API on an EC2 instance for a class project. On my local machine (Mac mini, 13.4.1, M2 chip) I enter the repository, run npm start, everything works. Through SSH I'...
Austin DiVito's user avatar
0 votes
2 answers
48 views

Express-validator checking field in cookies instead of body

I have the following validator: const validationSchema = checkSchema({ 'applicant.name': { exists: true, errorMessage: 'Name field is required', }, }); and the beginning of ...
SadCoder's user avatar
0 votes
0 answers
18 views

how to fix this.validator is not a function

validationResult is not working well and returns typeError validatorResult is not a function but the problem still continues ValidatorFields.js file: const { validationResult } = require("express-...
Taner Özer's user avatar
0 votes
0 answers
29 views

how to Use express validator (7.0.2) for route.post()

// here i using route/users.js var express = require('express'); var router = express.Router(); const { body, validationResult } = require('express-validator'); var User = require('../models/user'); ...
solaiman ibna Khair's user avatar
-1 votes
1 answer
59 views

Express-validator 7.0.1 isDate() always return false

The following code works for express-validator 6.14.2. const checkDate = check("date").isDate(); // simplified but you get the idea, app.post( "/path1", [checkDate], ...
user3552178's user avatar
  • 2,769
0 votes
0 answers
28 views

I want to use schema-validation technique (checkSchema) of express validator for validating the body of the request and return any errors

router.post( "/", [ body("name").isLength({ min: 3 }), body("email").isEmail(), body("password").isLength({ min: 5 }), ], (req, res) => { ...
Shashank K Prabhu's user avatar
-1 votes
1 answer
29 views

Why does express-validator not detect missing fields when validating XML input?

I have an express-based server that parses xml rather than json (using body-parser-xml). I then use express-validator to validate the body input like this (the real code doesn't look quite like this, ...
DaedalusAlpha's user avatar
0 votes
0 answers
26 views

Validation a request as function without middleware

is there a use of express-validator as non-middleware, just a function to send request json and take errors as a return. import express from 'express'; import { body, validationResult } from 'express-...
Septimus's user avatar
-1 votes
1 answer
53 views

Is there any way to check the JSON string with express-validator?

The express-validator attempts to examine the "email" field inside the "userData" object as follows. userRouter.post('/', [ header('type').isIn(...), body('userData')....
Minwoo Kim's user avatar
0 votes
1 answer
35 views

Express-validator middleware either times out, is not able to read req.params, or complains about being a promise instead of a call back function

I am using express-validator for an Express backend application. I have used the validator in some routes already, but in this case, I am trying to make a DB call and based on a value returning a ...
fixedraincoat's user avatar
0 votes
0 answers
18 views

Express Validator: field mandatory if another field has a value, but rejected otherwise?

I'm trying to write a validation chain with the following reqs: Field type is mandatory and one of a set of values Field negativeName is mandatory if type === 'binary' but otherwise shouldn't be ...
sernaferna's user avatar
-1 votes
1 answer
38 views

Ajax 400 error after Express Validator runs server-side validation

I am trying to fix a form handler that always throws a 400 error after middleware validation. The middleware validation goes like this: const contactValidate = [ check('name') .exists() ....
Andrew Buccellato's user avatar
0 votes
0 answers
27 views

Node js using express-validation

I have this file validation: import { check } from "express-validator"; exports.validateAuthor = [ check('name', 'name is required').not().isEmpty() ] and I used it on: import { Router ...
Jhon Estrada's user avatar
0 votes
0 answers
132 views

Using express-validator to validate array object value from req.body

I am trying to send an array of the object as a form-data using postman. Then validate the data using express-validate I created a function that will handle the validation process of my body. validate....
Lion Smith's user avatar
0 votes
1 answer
19 views

How can I make ExpressValidator validate empty array OR contents of array

I have an array that passes through my validator, which currently looks like this: expressValidator.body('animals.*').custom(checkAnimal).withMessage('Must provide an array containing valid animals') ...
OhkaBaka's user avatar
  • 339
1 vote
2 answers
30 views

Validating resource existence before performing updates or deletes in Expressjs

I'm developing a web application using Express.js and MongoDB, and I'm implementing validation with express-validator for updating or deleting resources. However, I have a concern about the ...
fjplaurr's user avatar
  • 1,870
0 votes
2 answers
61 views

express-validator: isEmail() won't report if body.email doesn't exist

Updated: express-validator 7.0.1, node 16.16.0 follow the 1st example at https://express-validator.github.io/docs/guides/validation-chain my initial code is like this app.post('/newsletter', body(&...
user3552178's user avatar
  • 2,769
0 votes
1 answer
92 views

Creating a custom validator function in Typescript for expressValidator class - parameter implicitly has 'any' type

I want to create a custom validation function for express-validator in typescript by extending the 'body' object. Looking at the support page I copied and pasted import { ExpressValidator } from '...
Pinocchio's user avatar
0 votes
0 answers
33 views

Express-validator - Validation not showing error messages

I have very basic idea about nodejs and i am learning it. I am testing login module and based on some existing questions and documentations. I have come up with these codes. Router.js router.post(&...
Roxx's user avatar
  • 3,788
1 vote
1 answer
449 views

Property 'path' does not exist on type 'ValidationError'. with express-validator 7.0.1

I am trying to access the path field from express-validator 7.0.1. But when I do, I receive an error "Property 'path' does not exist on type 'ValidationError'".: import express, { Request, ...
Stanley Ulili's user avatar
2 votes
2 answers
198 views

Use isStrongPassword in validation schema

I'm trying to define a schema using express-validator in which I set the "isStrongPassword" option. The "usernameSchema" works fine, but the "passwordSchema" doesn't pass ...
Jonas Q.'s user avatar
-1 votes
1 answer
307 views

Jest.spyOn return an error -"Cannot use spyOn on a primitive value; undefined given" Express.js package "express-validator"

I use Express.js, to validate requests, I use a package express-validator. And I want to test the controller: import { validationResult } from "express-validator"; class ...
BuGaGa's user avatar
  • 351
0 votes
0 answers
122 views

jest mock express-validator validationResult

Is it possible to mock validationResult, just to prove it was called and that the controller acts accordingly when the validation fails? postSetup: async function (req: Request, res: Response): ...
Andrew Johns's user avatar
0 votes
0 answers
33 views

express-validation sequential processing [duplicate]

I am following this guide running-imperatively and trying to implement the sequential processing sample. const validate = validations => { return async (req, res, next) => { for (let ...
vava044's user avatar
  • 51
0 votes
2 answers
271 views

Express Validator to validate time

I want to validate Time like this 18:14 with express-validator. When i used isTime as stated in validator like this body("StartTime").isTime().withMessage("Value must be time with HH:MM ...
Aflah vp's user avatar
  • 323
0 votes
0 answers
228 views

Validating JSON/Javascript objects using express-validate

I have a web app with a form that sends multipart/form-data to my Express server. The form contains various types of data; strings, numbers, objects/arrays and a file. Everything gets sent as a string ...
kougami's user avatar
  • 746
0 votes
0 answers
59 views

express-validator - validate images array

I'm working on a project using Multer to upload an array of images in a field named "images". I need to validate that all images are either PNG or JPG, but I'm having trouble getting the ...
BautistaCodes's user avatar
1 vote
0 answers
61 views

Validating Birthday with express validator

check('birthday').isDate({format:"YYYY-MM-DD"}).custom((value)=>{ var dob = new Date(value) var year = dob.getFullYear() var today = new Date(); var age = today....
Aayushi Vaghasiya's user avatar
0 votes
0 answers
120 views

Redeclare type of the block-scoped variable using ambient module

I'm using 'express-validator' library. I'd like to redefine a type of one of its exported functions body. The function declaration in the library: export declare const body: (fields?: string | string[]...
letelete's user avatar
0 votes
0 answers
22 views

oneOf() express-validator is throwing error defying my wish for a resolution

I created a function to run express-validator oneOf() var oneoftest = oneOf([ check("ordertype").equals("Delivery"), check("streetnumber").isIn(["one",&...
Marco's user avatar
  • 1,115
1 vote
1 answer
86 views

express-validator conditional validation with if/else

In an expressjs app, I have express-validator to validate form input. I have an order endpoint that I need to validate the fields provided but can't figure out how to do conditional validation. The ...
Marco's user avatar
  • 1,115
0 votes
1 answer
472 views

How to validate only when param is exist in express-validator

I'm building a update user method in express. The data is dynamic. Like: I have 2 field that can be updated: name, phone_number, In 1 request, the data can be only phone_number or name or both. I use ...
kan's user avatar
  • 189
0 votes
1 answer
60 views

Handling Express Validator in a middleware

The classic way shown in tutorials would be: Router.post('/add-post', addPostValidation(), addPost) But what if I want to do the validation in a middleware like this: The router: Router.post('/add-...
user avatar
0 votes
1 answer
48 views

Why bcrypt.compareSync() is always returning me a false

I'm comparing the password from a FORM in a login view, with the password in a database in .JSON. But even when I see in the console that both are the same, the method is always returning a false. ...
Manuel Alejandro Garca Andrade's user avatar
0 votes
0 answers
40 views

Express Validator email normalizeEmail with org mail ending

I'm using the express validator method normalizeEmail, that suppose to prevent the + sign: If the user input is [email protected] it should convert to [email protected]. For some reason if I ...
Lior Shein's user avatar
0 votes
3 answers
171 views

TypeError: validator.escape is not a function - ([email protected] package)

Codecademy video: link Explanation: As part of my Codecademy Back-End Engineer training, I have to do a project outside of their platform. The goal of this project is to make sure a node application ...
vetheve's user avatar
  • 209
0 votes
1 answer
69 views

How can a function return an array of validators and also call next()?

I need a function that takes the request body and conditionally creates the validators that will be used on the request. I figured the best way to do this is by creating middleware but I'm running ...
exloser's user avatar
  • 37
0 votes
0 answers
75 views

How to display alert messages in each inputs using express validation and handlebars

I want to display an alert message in frequent input in handlebars view (under each input has its message) {{#each answers}} <!-- =================================...
Eman Lajam's user avatar
0 votes
1 answer
56 views

Body errors not triggering express-validator

The validation middleware code is not triggered in the code I created, although all the logging flags are executed. const { check, validationResult } = require("express-validator"); module....
rainydaymatt's user avatar
0 votes
0 answers
40 views

users.insertOne()` buffering timed out after 10000ms

I have provided the whole code it's a simple code for the user's data to MongoDB database but it's not saving in MongoDB. and i can't find out where I am wrong, I have tried to async await the ...
wasif mehmood's user avatar
0 votes
1 answer
39 views

Access Error Object at Error Middleware Handler

This is my custom error validation code : .custom(async (username) => { const user = await UserModel.findOne({ username }) if (user) throw new ...
me noob's user avatar
  • 579
0 votes
1 answer
243 views

Express-validator: How can i use date birthday validator with checkschema?

I'm developing a project with a form and I need use a validator. I choice express-validator to this job. I am using express-validator with checkschema format and I can't to validate the date. The ...
André Bottentuit's user avatar
0 votes
1 answer
380 views

How to call express-validator from middleware function?

I have been struggling to call express-validator function from a middleware function. I can see execution is happing to express-validator but nothing is validating. Below is the code snipped: router....
justAnAnotherCoder's user avatar
-1 votes
1 answer
164 views

Express validator validate if data provided

I'm using express-validator for validation for mandatory fields. But some fields are not mandatory like date of birth, price. I want to validate if these fields contains a value, like if I provide the ...
Debabrata Roy's user avatar
0 votes
1 answer
475 views

How to reuse validation rules for different endpoints using Express Validator?

I want to reuse Express Validator schemas in different endpoints, for instance in POST, and PUT requests, I don't want to create two different schemas (one for each endpoint), because if something ...
Luis Carlos Cruz Castillo's user avatar
0 votes
0 answers
16 views

Express-validator: How to warn user that a request body field becomes obsolete

so we're retiring a field from request body, we made this field to be optional 1st. At the same time, how to display the warning to user ? app.patch( "/v1/myUrl", [ body(&...
user3552178's user avatar
  • 2,769

1
2 3 4 5
10