1"use strict";(self.webpackChunk=self.webpackChunk||[]).push([[2912],{83772(e,n,s){s.r(n),s.d(n,{assets:()=>t,contentTitle:()=>a,default:()=>h,frontMatter:()=>d,metadata:()=>c,toc:()=>o});const c=JSON.parse('{"id":"api/check","title":"check","description":"The check() function is the main API used for validating and sanitizing HTTP requests with express-validator.","source":"@site/../docs/api/check.md","sourceDirName":"api","slug":"/api/check","permalink":"/docs/next/api/check","draft":false,"unlisted":false,"editUrl":"https://github.com/express-validator/express-validator/edit/master/docs/../docs/api/check.md","tags":[],"version":"current","frontMatter":{"title":"check"},"sidebar":"api","next":{"title":"checkExact","permalink":"/docs/next/api/check-exact"}}');var i=s(62540),r=s(43023);const d={title:"check"},a=void 0,t={},o=[{value:"<code>check()</code>",id:"check",level:2},{value:"<code>body()</code>",id:"body",level:2},{value:"<code>cookie()</code>",id:"cookie",level:2},{value:"<code>header()</code>",id:"header",level:2},{value:"<code>param()</code>",id:"param",level:2},{value:"<code>query()</code>",id:"query",level:2}];function l(e){const n={a:"a",code:"code",h2:"h2",li:"li",p:"p",pre:"pre",strong:"strong",table:"table",tbody:"tbody",td:"td",th:"th",thead:"thead",tr:"tr",ul:"ul",...(0,r.R)(),...e.components};return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsxs)(n.p,{children:["The ",(0,i.jsx)(n.code,{children:"check()"})," function is the main API used for validating and sanitizing HTTP requests with express-validator.\nIt gives you access to all of the built-in validators, sanitizers, and a bunch of other utility\nfunctions to shape the validation just the way you need."]}),"\n",(0,i.jsx)(n.h2,{id:"check",children:(0,i.jsx)(n.code,{children:"check()"})}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-ts",children:"import { check } from 'express-validator';\ncheck(fields?: string | string[], message?: any): ValidationChain\n"})}),"\n",(0,i.jsx)(n.p,{children:(0,i.jsx)(n.strong,{children:"Parameters:"})}),"\n",(0,i.jsxs)(n.table,{children:[(0,i.jsx)(n.thead,{children:(0,i.jsxs)(n.tr,{children:[(0,i.jsx)(n.th,{children:"Name"}),(0,i.jsx)(n.th,{children:"Description"})]})}),(0,i.jsxs)(n.tbody,{children:[(0,i.jsxs)(n.tr,{children:[(0,i.jsx)(n.td,{children:(0,i.jsx)(n.code,{children:"fields"})}),(0,i.jsxs)(n.td,{children:["One or more field names to select. If omitted, selects the ",(0,i.jsx)(n.a,{href:"/docs/next/guides/field-selection#whole-body-selection",children:"whole request location"}),"."]})]}),(0,i.jsxs)(n.tr,{children:[(0,i.jsx)(n.td,{children:(0,i.jsx)(n.code,{children:"message"})}),(0,i.jsx)(n.td,{children:"Which error message to use when a validator doesn't specify one."})]})]})]}),"\n",(0,i.jsxs)(n.p,{children:["Creates a ",(0,i.jsx)(n.a,{href:"/docs/next/api/validation-chain",children:"validation chain"})," for one or more fields.\nFields are selected from any of the following request locations:"]}),"\n",(0,i.jsxs)(n.ul,{children:["\n",(0,i.jsx)(n.li,{children:(0,i.jsx)(n.code,{children:"req.body"})}),"\n",(0,i.jsx)(n.li,{children:(0,i.jsx)(n.code,{children:"req.cookies"})}),"\n",(0,i.jsx)(n.li,{children:(0,i.jsx)(n.code,{children:"req.headers"})}),"\n",(0,i.jsx)(n.li,{children:(0,i.jsx)(n.code,{children:"req.query"})}),"\n",(0,i.jsx)(n.li,{children:(0,i.jsx)(n.code,{children:"req.params"})}),"\n"]}),"\n",(0,i.jsx)(n.p,{children:"If any of the fields is present in more than one location, then all instances of that field value\nare processed by the validation chain."}),"\n",(0,i.jsx)(n.h2,{id:"body",children:(0,i.jsx)(n.code,{children:"body()"})}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-ts",children:"import { body } from 'express-validator';\nbody(fields?: string | string[], message?: any): ValidationChain\n"})}),"\n",(0,i.jsxs)(n.p,{children:["Same as ",(0,i.jsx)(n.a,{href:"#check",children:(0,i.jsx)(n.code,{children:"check()"})}),", but only checking ",(0,i.jsx)(n.code,{children:"req.body"}),"."]}),"\n",(0,i.jsx)(n.h2,{id:"cookie",children:(0,i.jsx)(n.code,{children:"cookie()"})}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-ts",children:"import { cookie } from 'express-validator';\ncookie(fields?: string | string[], message?: any): ValidationChain\n"})}),"\n",(0,i.jsxs)(n.p,{children:["Same as ",(0,i.jsx)(n.a,{href:"#check",children:(0,i.jsx)(n.code,{children:"check()"})}),", but only checking ",(0,i.jsx)(n.code,{children:"req.cookies"}),"."]}),"\n",(0,i.jsx)(n.h2,{id:"header",children:(0,i.jsx)(n.code,{children:"header()"})}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-ts",children:"import { header } from 'express-validator';\nheader(fields?: string | string[], message?: any): ValidationChain\n"})}),"\n",(0,i.jsxs)(n.p,{children:["Same as ",(0,i.jsx)(n.a,{href:"#check",children:(0,i.jsx)(n.code,{children:"check()"})}),", but only checking ",(0,i.jsx)(n.code,{children:"req.headers"}),"."]}),"\n",(0,i.jsx)(n.h2,{id:"param",children:(0,i.jsx)(n.code,{children:"param()"})}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-ts",children:"import { param } from 'express-validator';\nparam(fields?: string | string[], message?: any): ValidationChain\n"})}),"\n",(0,i.jsxs)(n.p,{children:["Same as ",(0,i.jsx)(n.a,{href:"#params",children:(0,i.jsx)(n.code,{children:"check()"})}),", but only checking ",(0,i.jsx)(n.code,{children:"req.params"}),"."]}),"\n",(0,i.jsx)(n.h2,{id:"query",children:(0,i.jsx)(n.code,{children:"query()"})}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-ts",children:"import { query } from 'express-validator';\nquery(fields?: string | string[], message?: any): ValidationChain\n"})}),"\n",(0,i.jsxs)(n.p,{children:["Same as ",(0,i.jsx)(n.a,{href:"#check",children:(0,i.jsx)(n.code,{children:"check()"})}),", but only checking ",(0,i.jsx)(n.code,{children:"req.query"}),"."]})]})}function h(e={}){const{wrapper:n}={...(0,r.R)(),...e.components};return n?(0,i.jsx)(n,{...e,children:(0,i.jsx)(l,{...e})}):l(e)}},43023(e,n,s){s.d(n,{R:()=>d,x:()=>a});var c=s(63696);const i={},r=c.createContext(i);function d(e){const n=c.useContext(r);return c.useMemo(function(){return"function"==typeof e?e(n):{...n,...e}},[n,e])}function a(e){let n;return n=e.disableParentContext?"function"==typeof e.components?e.components(i):e.components||i:d(e.components),c.createElement(r.Provider,{value:n},e.children)}}}]);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.