Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

269
Views
How to use the blacklist method from express-validator

I have the following post request that validates some data:

app.post(
  "/review",
  [
    // Add the middleware to validate email and restaurant info below:
    check("email").isEmail(),
    check("restaurant").notEmpty().blacklist("<>"),
    check("rating").isNumeric(),
    check("review").notEmpty().blacklist("<>")
  ],
// ...

The documentation for validator.js demonstrates to use the blacklist method as follows:


blacklist(input, '\\[\\]')

Considering the context of how i'm adding my middleware, it's a bit confusing to understand what exactly should be the input parameter. I'm already using the check method to look for the input field, what exactly should go in the blacklist method?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Since you are using [express-validator][1] which works as a wrapper over [validator.js][1], the input is injected to the blacklist method by the express-validator and in your case, since you are using check() method of express-validator the input will be the parameter with the label that you have provided as the argument to check() method which might exist in any of the following request objects:

  • req.body
  • req.cookies
  • req.headers
  • req.params
  • req.query

In your case for check("restaurant").notEmpty().blacklist("<>"), a parameter with the label of restaurant will be extract from either one of the aforementioned request objects and for check("review").notEmpty().blacklist("<>"), a parameter with the label review will be extracted.

So the only argument that should be provided for the check method is a regex string which specifies the characters that must get removed.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!