Questions tagged [express-validator]
An express.js middleware library for validation and sanitization.
463
questions
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 ...
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('/...
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 ...
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";
...
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'...
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 ...
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-...
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');
...
-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],
...
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) => {
...
-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, ...
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-...
-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')....
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 ...
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 ...
-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()
....
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 ...
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....
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')
...
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 ...
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(&...
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 '...
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(&...
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, ...
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 ...
-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 ...
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): ...
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 ...
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 ...
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 ...
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 ...
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....
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[]...
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",&...
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 ...
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 ...
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-...
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.
...
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 ...
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 ...
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 ...
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}}
<!-- =================================...
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....
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 ...
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 ...
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 ...
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....
-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 ...
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 ...
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(&...