Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

271
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda