Questions tagged [express-validator]
An express.js middleware library for validation and sanitization.
407
questions
0
votes
0
answers
17
views
Express-validator input sanitize inside a middleware or router callback?
I'm trying to improve the security of my express app by using the express-validator package, I figured out that I could use it in two different ways.
The first inside a middleware:
const {check}=...
0
votes
0
answers
22
views
Validating an array of objects using express-validator
I'm facing an issue with express-validator on node.js to validate an array of objects that is being passed from my request body. req.body.subjects holds the data below
[
{
"title&...
0
votes
0
answers
13
views
How to validate a date to be after another date using express validator
How to check if start_of_application is before end_of_application?
const { body } = require("express-validator");
exports.createJob = () => {
return [
body("...
0
votes
0
answers
13
views
How to validate the array of CSV files that were received using the Multer and express-validator node module
When I use the "express-fileupload" node-module as middleware, I get the req.files structure like below as object,
{
userList: {
name: 'users-list.csv',
data: <Buffer 22 68 63 ...
1
vote
1
answer
69
views
express-validator isStrongPassword() function is not working
I'm trying to do validation test by using express-validator.
so far everything is working good except isStrongPassword()
import {check} from "express-validator"
const val =
check('...
0
votes
0
answers
30
views
How do I display API error messages using Formik?
I am using Formik/Yup in my frontend to validate form data, which is working fine. Once the form is submitted, I have the backend Express server set to return an array of errors like:
{username: '...
0
votes
1
answer
38
views
Calling third party middlewares inside a custom middleware in NodeJS Express
I'm learning NodesJS Express. I am using Express-Validator for my testing purposes.
Here is my testing program.
const express = require("express");
const app = express();
const port = 5000;
...
1
vote
1
answer
44
views
How to validate arrays/objects in express-validator using body(), checking only the specified fields?
I have my field names in an array like these:
const baseFields = [
'employeeNumber',
'firstName',
'lastName',
'trEmail',
'position'
];
Those are the input fields I only have to care about being ...
0
votes
0
answers
57
views
Cross site scripting - express-validator escape on json object
I have post call api implemented in NodeJs. It has big json request.
For cross site scripting XSS prevention, I am working to sanitize request with express-validator.
I have implemented below one to ...
0
votes
1
answer
38
views
Express validator custom function
I'm trying to write a custom validator for an express API. I can't figure out how I can reject incorrect values from the custom validator. Here's what I have:
function validateInput(value) {
if (!...
0
votes
0
answers
26
views
Show only one error per validation in Express-Validator
I'm making a validation chain for a SignUp Middleware:
export const SignUpValidator: ValidationChain[] = [
body('email')
.exists().withMessage('1st Error')
.not().isEmpty()....
0
votes
1
answer
46
views
express-validator can't evaluate body fields when form-data is used
I am trying to use express-validator in combination with multer to validate the body components of a POST request that also contains an image, headers, and params. I have tried using the body() style ...
0
votes
0
answers
44
views
Express Validator - If exists for nested array of object
{
"orderId": "3",
"storeId": "1",
"products": [
"productId": "123",
{
"prescriptions&...
0
votes
1
answer
26
views
Express Server how to post data from postman
I just built a express server with mongodb and trying to request it using postman but getting error
So this is the code for the route
router.post(
'/',
check('email', 'Please include a valid ...
1
vote
2
answers
88
views
Express-Validator "validationResult" returns [object Object]
I'm modifying the Error handling of the Express-Validator middleware to go through my custom Error Handling middleware but the message of the validationResult resolves to [object Object].
Express-...
0
votes
1
answer
36
views
How can I hide certain attribute from response with Bookshelf?
I am building a simple REST API. When registering a new user, my API returns:
{
"status": "success",
"data": {
"email": "test13@test.com&...
1
vote
2
answers
104
views
express-validator doesn't check anything
Here is my code. I want to check that name is alphabetic and have more than 2 characters, but this code doesn't generate any error.
const {body, validationResult} = require('express-validator');
...
0
votes
0
answers
32
views
Unexpected Eof exception when req.body from nodejs is sent to a springboot rest controller
I have a nodejs application which receives input in the form of a json from frontend.
Input request
{
"name":"tina",
"address":{
"doorNo":"54",
"...
0
votes
0
answers
23
views
Validation does not work when performing a custom validation, Express Validator Express
Using Express Validator I need to verify what comes in the request but I always get an error with Express Validator indicating "Invalid value".
This is generated with this code in my route:
...
0
votes
1
answer
21
views
checkSchema syntax documentation
I would like to use the checkSchema method instead of what I am currently doing with all the checks on the post route in an array. The problem I have is I can't find good documentation on the syntax ...
0
votes
0
answers
84
views
validate nested array using express validator
I'm using express validator to validate req.body .
I have nested arrays I wanted to validate. apply[] and apply.fields[]. the apply array can hold more than an item.
apply :[
{
...
0
votes
0
answers
30
views
Multer Prevent uploading if one of the fields is missing
I'm using multer to upload documents.
So i i have 3 fields for users to upload the files .
I'm also using express-validator to validate the fields(wether they are empty or not).
Upload = multer({
...
0
votes
1
answer
37
views
req.checkBody is not a function with Express-Validator NODEJS
Hi I'm trying doing a login page, after clicking on submit I'm getting this error with express-validator version 5.3.1
req.checkBody is not a function
TypeError: req.checkBody is not a function
at ...
1
vote
0
answers
62
views
Custom function (Select Statement) using Express-Validator using Knex.js and SQLITE
first of all I'm a javascript beginner and I'm just trying to teach myself the different components.
I have written an API using Node.js, Express, SQLITE and Knex. Now I want to run a check with the ...
0
votes
1
answer
56
views
Returning a custom status code from express-validator .isEmail()
I have little experience with Node, and even less on Express/express-validator (been more of a NestJS guy). I'm tweaking some validations on an endpoint, and almost everything is working as it should. ...
0
votes
0
answers
41
views
express-validator custom validator pass but not return request
I'm trying to create a custom validator to create a generic enum validator, but when my rule passes to test, the request does not return it's as if nextFunction didn't trigger. When my rule fails ...
0
votes
1
answer
48
views
Pass two values to custom validation with express-validation
I need to receive two values to search for a subdocument using the main ID of the document and then another ID of the subdocument.
I receive these ID's by the parameters and using express-validator ...
0
votes
0
answers
70
views
swagger - extract parameter info from express-validation
I'm new to node, swagger etc.
I'm working on a node.js app, I added some endpoints and using express-validation package I configured validators for my end points.
I now started using also swagger-...
0
votes
0
answers
144
views
How do you display express validator error in react frontend?
I'm trying to get the error thrown by express-validator to render on the frontend for the user. The error will log out in the terminal, but I can't figure out how to send that data to the frontend and ...
0
votes
0
answers
35
views
Sanitize optional undefined values as null
I'm trying to sanitize undefined optional values to be null.
I tried this:
body('value').isNumeric().optional().default(null)
But it only works when value is not allowed to be .optional().
I also ...
0
votes
0
answers
30
views
Express Validator - What is difference between withDefaults() and formatWith()
I am starting to learn MERN, and checking the express-validator documentation. I am not able to determine a use case where withDefaults() and formatWith() will make a difference.
Documentation Links - ...
0
votes
1
answer
328
views
express-validator checkSchema not raise errors
I'm using checkSchema as middleware to validate some query input. It's working but it is not throwing errors.
Here's part of my code:
Router
import express from "express";
import * as ...
1
vote
1
answer
49
views
Validate an array property only if another property inside the same object is true with express-validator
I'm using express-validator to validate the requests to my express application and I have one endpoint that receives one object in which one of the properties is an array of objects. It looks like ...
1
vote
2
answers
289
views
express-validator: is it possible to chain different user validation rules?
I have the following rules which are almost similar except for one route the param is optional and the other it is mandatory.
need to combine them so that i can use single code interchangeably for ...
5
votes
1
answer
77
views
express validator : how to check for "+xyz" using query check?
i am trying to validate/allow set of words like +originalUrl, -originalUrl , +createdAt using express-validator.
it supports .matches which allows patterns. https://github.com/validatorjs/validator.js/...
0
votes
1
answer
228
views
Validate form-data data with express-validator
I have the problem that express-validator is not validating my data that comes from form-data when I send it empty or full data in postman it always shows me the errors that I validate in express-...
0
votes
1
answer
260
views
How to make a function validator for express-validator and use it as Middleware?
I have this validator in my register route:
router.post(
"/register",
// username must be an email
body("username")
.isLength({ min: 4 })
.withMessage("username ...
1
vote
1
answer
2k
views
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 {
...
0
votes
1
answer
93
views
Email validation is not working in node js
I have written code to perform email validation and password validation, but it is not returning any error if condition is not satisfied, didn't get any idea what is wrong with my code.
code in ...
1
vote
1
answer
58
views
How I validate a array of object inside a Object in request body with express validator
Request Body is like
{
"name":"nazmul Haque",
"age" : "26",
"favoriteBooks" :
[
{
...
0
votes
0
answers
26
views
My expresss-validator doesn't work correctly, it always shows an error
I'm using express-validator to validate user's input, but it always shows an error even if input is correct.
My app.js
var createError = require('http-errors');
var express = require('express');
var ...
0
votes
2
answers
252
views
Installed module 'express-validator' cannot be found in NodeJS/Express project
I want to validate the input that the endpoint receives upon invoking it. Therefore, I installed express-validator in my NodeJS web application. However, when I try to make use of it, it throws the ...
0
votes
0
answers
41
views
Handling errors of customSanitizer of express-validator?
I am using express-validator for server-side validation. I am receiving a multipart/form-data from. So for this, I am using formidable.
So I created a middleware handleFormData which parses the form ...
0
votes
2
answers
199
views
Express Validator: Custom validation with asynchronous functions
I'm currently trying to validate some inputs in Express using express-validator. I know that it's typical to pass it as a separate middleware into the route, but I needed access to the res object, so ...
0
votes
0
answers
97
views
Express validator validate array of objects
I'm currently trying to make a Quiz. Each question has a certain required answers. My current config file with questions, answers and requiredAnswers is the following:
[
{
"question": &...
-1
votes
1
answer
60
views
All considered symbols in validator.js?
I use the .isStrongPassword() function from validator.js. By default it checks if the password contains at least one symbol. Unfortunately I can't find a set of all the chars that are considered a ...
0
votes
0
answers
28
views
Unexpected error returned from express-validator while using custom validator
I am trying to check if the products sent from the client is an array and not empty using a custom validator in express-validator.
However when I send the correct json, I still get an error which ...
0
votes
1
answer
180
views
Express - Validation express-validator does not show errors
I'm sure this is not a problem instead I'm not using it the right way.
I want to validate user request body and according to documentation, all work is done in the route file. And I divided my work ...
1
vote
0
answers
103
views
Express-validator returning empty array of erros even when there are errors
I am trying to validate user input with express validator and I get an empty array of errors which is incorrect because I sent the wrong input to test. When I console.log(errors), I get this : Result {...
0
votes
0
answers
90
views
Express js Sanitize does not work (Express-validate)
I want to sanitize my user inputs, so that no xss is possible. I know that this works in PHP which is why it has to somehow work in node js aswell. I want to remove htmlchars, stripslashes and trim ...