Skip to main content
Version: Next

check

The check() function is the main API used for validating and sanitizing HTTP requests with express-validator. It gives you access to all of the built-in validators, sanitizers, and a bunch of other utility functions to shape the validation just the way you need.

check()

import { check } from 'express-validator';
check(fields?: string | string[], message?: any): ValidationChain

Parameters:

NameDescription
fieldsOne or more field names to select. If omitted, selects the whole request location.
messageWhich error message to use when a validator doesn't specify one.

Creates a validation chain for one or more fields. Fields are selected from any of the following request locations:

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

If any of the fields is present in more than one location, then all instances of that field value are processed by the validation chain.

body()

import { body } from 'express-validator';
body(fields?: string | string[], message?: any): ValidationChain

Same as check(), but only checking req.body.

import { cookie } from 'express-validator';
cookie(fields?: string | string[], message?: any): ValidationChain

Same as check(), but only checking req.cookies.

import { header } from 'express-validator';
header(fields?: string | string[], message?: any): ValidationChain

Same as check(), but only checking req.headers.

param()

import { param } from 'express-validator';
param(fields?: string | string[], message?: any): ValidationChain

Same as check(), but only checking req.params.

query()

import { query } from 'express-validator';
query(fields?: string | string[], message?: any): ValidationChain

Same as check(), but only checking req.query.