express-validator

  • Version 6.13.0
  • Published
  • 96.8 kB
  • 2 dependencies
  • MIT license

Install

npm i express-validator
yarn add express-validator
pnpm add express-validator

Overview

Express middleware for the validator module.

Index

Variables

Functions

Classes

Interfaces

Type Aliases

Namespaces

Variables

variable validationResult

const validationResult: ResultFactory<ValidationError> & {
withDefaults: typeof withDefaults;
};

    Functions

    function body

    body: (
    fields?: string | string[] | undefined,
    message?: any
    ) => import('..').ValidationChain;

      function buildCheckFunction

      buildCheckFunction: (
      locations: Location[]
      ) => (
      fields?: string | string[] | undefined,
      message?: any
      ) => import('..').ValidationChain;

        function buildSanitizeFunction

        buildSanitizeFunction: (
        locations: Location[]
        ) => (fields?: string | string[] | undefined) => import('..').SanitizationChain;

          function check

          check: (
          fields?: string | string[] | undefined,
          message?: any
          ) => import('..').ValidationChain;

            function checkSchema

            checkSchema: (
            schema: Schema,
            defaultLocations?: Location[]
            ) => ValidationChain[] & { run: (req: Request) => Promise<ResultWithContext[]> };
              cookie: (
              fields?: string | string[] | undefined,
              message?: any
              ) => import('..').ValidationChain;
                header: (
                fields?: string | string[] | undefined,
                message?: any
                ) => import('..').ValidationChain;

                  function matchedData

                  matchedData: (
                  req: Request,
                  options?: Partial<MatchedDataOptions>
                  ) => Record<string, any>;

                    function oneOf

                    oneOf: {
                    (
                    chains: (ValidationChain | ValidationChain[])[],
                    message?: OneOfCustomMessageBuilder
                    ): Middleware & { run: (req: Request) => Promise<Result> };
                    (chains: (ValidationChain | ValidationChain[])[], message?: any): Middleware & {
                    run: (req: Request) => Promise<Result<any>>;
                    };
                    };

                      function param

                      param: (
                      fields?: string | string[] | undefined,
                      message?: any
                      ) => import('..').ValidationChain;

                        function query

                        query: (
                        fields?: string | string[] | undefined,
                        message?: any
                        ) => import('..').ValidationChain;

                          function sanitize

                          sanitize: (
                          fields?: string | string[] | undefined
                          ) => import('..').SanitizationChain;

                            function sanitizeBody

                            sanitizeBody: (
                            fields?: string | string[] | undefined
                            ) => import('..').SanitizationChain;

                              function sanitizeCookie

                              sanitizeCookie: (
                              fields?: string | string[] | undefined
                              ) => import('..').SanitizationChain;

                                function sanitizeParam

                                sanitizeParam: (
                                fields?: string | string[] | undefined
                                ) => import('..').SanitizationChain;

                                  function sanitizeQuery

                                  sanitizeQuery: (
                                  fields?: string | string[] | undefined
                                  ) => import('..').SanitizationChain;

                                    Classes

                                    class Result

                                    class Result<T = any> {}

                                      constructor

                                      constructor(formatter: ErrorFormatter<T>, errors: readonly ValidationError[]);

                                        method array

                                        array: (options?: { onlyFirstError?: boolean }) => T[];

                                          method formatWith

                                          formatWith: <T2>(formatter: ErrorFormatter<T2>) => Result<T2>;

                                            method isEmpty

                                            isEmpty: () => boolean;

                                              method mapped

                                              mapped: () => Record<string, T>;

                                                method throw

                                                throw: () => void;

                                                  Interfaces

                                                  interface SanitizationChain

                                                  interface SanitizationChain extends Sanitizers<SanitizationChain>, ContextRunner {}

                                                    property builder

                                                    builder: ContextBuilder;

                                                      call signature

                                                      (req: Request, res: any, next: (errors?: any) => void): void;

                                                        interface ValidationChain

                                                        interface ValidationChain
                                                        extends Validators<ValidationChain>,
                                                        Sanitizers<ValidationChain>,
                                                        ContextHandler<ValidationChain>,
                                                        ContextRunner {}

                                                          property builder

                                                          builder: ContextBuilder;

                                                            call signature

                                                            (req: Request, res: any, next: (error?: any) => void): void;

                                                              Type Aliases

                                                              type CustomSanitizer

                                                              type CustomSanitizer = (input: any, meta: Meta) => any;

                                                                type CustomValidator

                                                                type CustomValidator = (input: any, meta: Meta) => any;

                                                                  type DynamicMessageCreator

                                                                  type DynamicMessageCreator = (value: any, meta: Meta) => any;

                                                                    type ErrorFormatter

                                                                    type ErrorFormatter<T = any> = (error: ValidationError) => T;

                                                                      type Location

                                                                      type Location = 'body' | 'cookies' | 'headers' | 'params' | 'query';

                                                                        type MatchedDataOptions

                                                                        type MatchedDataOptions = {
                                                                        includeOptionals: boolean;
                                                                        locations: Location[];
                                                                        onlyValidData: boolean;
                                                                        };

                                                                          type Meta

                                                                          type Meta = {
                                                                          req: Request;
                                                                          location: Location;
                                                                          path: string;
                                                                          };

                                                                            type OneOfCustomMessageBuilder

                                                                            type OneOfCustomMessageBuilder = (options: { req: Request }) => any;

                                                                              type ParamSchema

                                                                              type ParamSchema = InternalParamSchema & {
                                                                              in?: Location | Location[];
                                                                              errorMessage?: DynamicMessageCreator | any;
                                                                              optional?:
                                                                              | true
                                                                              | {
                                                                              options?: Partial<Optional>;
                                                                              };
                                                                              };
                                                                              • Defines a schema of validations/sanitizations plus a general validation error message and possible field locations.

                                                                              type ResultFactory

                                                                              type ResultFactory<T> = (req: Request) => Result<T>;

                                                                                type Schema

                                                                                type Schema = Record<string, ParamSchema>;
                                                                                • Defines a mapping from field name to a validations/sanitizations schema.

                                                                                type ValidationError

                                                                                type ValidationError =
                                                                                | {
                                                                                param: '_error';
                                                                                msg: any;
                                                                                nestedErrors: ValidationError[];
                                                                                location?: undefined;
                                                                                value?: undefined;
                                                                                }
                                                                                | {
                                                                                location: Location;
                                                                                param: string;
                                                                                value: any;
                                                                                msg: any;
                                                                                nestedErrors?: unknown[];
                                                                                };

                                                                                  type ValidationParamSchema

                                                                                  type ValidationParamSchema = ParamSchema;
                                                                                  • Deprecated

                                                                                    Only here for v5 compatibility. Please use ParamSchema instead.

                                                                                  type ValidationSchema

                                                                                  type ValidationSchema = Schema;
                                                                                  • Deprecated

                                                                                    Only here for v5 compatibility. Please use Schema instead.

                                                                                  Namespaces

                                                                                  namespace validator

                                                                                  module 'validator' {}

                                                                                    function blacklist

                                                                                    blacklist: (str: string, chars: string) => string;

                                                                                      function contains

                                                                                      contains: (
                                                                                      str: string,
                                                                                      elem: any,
                                                                                      options?: import('../src/options').ContainsOptions
                                                                                      ) => boolean;

                                                                                        function equals

                                                                                        equals: (str: string, comparison: string) => boolean;

                                                                                          function escape

                                                                                          escape: (str: string) => string;

                                                                                            function isAfter

                                                                                            isAfter: (str: string, date?: string) => boolean;

                                                                                              function isAlpha

                                                                                              isAlpha: (
                                                                                              str: string,
                                                                                              locale?: import('../src/options').AlphaLocale,
                                                                                              options?: import('../src/options').IsAlphaOptions
                                                                                              ) => boolean;

                                                                                                function isAlphanumeric

                                                                                                isAlphanumeric: (
                                                                                                str: string,
                                                                                                locale?: import('../src/options').AlphanumericLocale,
                                                                                                options?: import('../src/options').IsAlphanumericOptions
                                                                                                ) => boolean;

                                                                                                  function isAscii

                                                                                                  isAscii: (str: string) => boolean;

                                                                                                    function isBase32

                                                                                                    isBase32: (str: string) => boolean;

                                                                                                      function isBase58

                                                                                                      isBase58: (str: string) => boolean;

                                                                                                        function isBase64

                                                                                                        isBase64: (
                                                                                                        str: string,
                                                                                                        options?: import('../src/options').IsBase64Options
                                                                                                        ) => boolean;

                                                                                                          function isBefore

                                                                                                          isBefore: (str: string, date?: string) => boolean;

                                                                                                            function isBIC

                                                                                                            isBIC: (str: string) => boolean;

                                                                                                              function isBoolean

                                                                                                              isBoolean: (str: string) => boolean;

                                                                                                                function isBtcAddress

                                                                                                                isBtcAddress: (str: string) => boolean;

                                                                                                                  function isByteLength

                                                                                                                  isByteLength: (
                                                                                                                  str: string,
                                                                                                                  options: import('../src/options').MinMaxOptions
                                                                                                                  ) => boolean;

                                                                                                                    function isCreditCard

                                                                                                                    isCreditCard: (str: string) => boolean;

                                                                                                                      function isCurrency

                                                                                                                      isCurrency: (
                                                                                                                      str: string,
                                                                                                                      options?: import('../src/options').IsCurrencyOptions
                                                                                                                      ) => boolean;

                                                                                                                        function isDataURI

                                                                                                                        isDataURI: (str: string) => boolean;

                                                                                                                          function isDate

                                                                                                                          isDate: (
                                                                                                                          str: string,
                                                                                                                          options?: import('../src/options').IsDateOptions
                                                                                                                          ) => boolean;

                                                                                                                            function isDecimal

                                                                                                                            isDecimal: (
                                                                                                                            str: string,
                                                                                                                            options?: import('../src/options').IsDecimalOptions
                                                                                                                            ) => boolean;

                                                                                                                              function isDivisibleBy

                                                                                                                              isDivisibleBy: (str: string, number: number) => boolean;

                                                                                                                                function isEAN

                                                                                                                                isEAN: (str: string) => boolean;

                                                                                                                                  function isEmail

                                                                                                                                  isEmail: (
                                                                                                                                  str: string,
                                                                                                                                  options?: import('../src/options').IsEmailOptions
                                                                                                                                  ) => boolean;

                                                                                                                                    function isEmpty

                                                                                                                                    isEmpty: (
                                                                                                                                    str: string,
                                                                                                                                    options?: import('../src/options').IsEmptyOptions
                                                                                                                                    ) => boolean;

                                                                                                                                      function isEthereumAddress

                                                                                                                                      isEthereumAddress: (str: string) => boolean;

                                                                                                                                        function isFloat

                                                                                                                                        isFloat: (
                                                                                                                                        str: string,
                                                                                                                                        options?: import('../src/options').IsFloatOptions
                                                                                                                                        ) => boolean;

                                                                                                                                          function isFQDN

                                                                                                                                          isFQDN: (
                                                                                                                                          str: string,
                                                                                                                                          options?: import('../src/options').IsFQDNOptions
                                                                                                                                          ) => boolean;

                                                                                                                                            function isFullWidth

                                                                                                                                            isFullWidth: (str: string) => boolean;

                                                                                                                                              function isHalfWidth

                                                                                                                                              isHalfWidth: (str: string) => boolean;

                                                                                                                                                function isHash

                                                                                                                                                isHash: (
                                                                                                                                                str: string,
                                                                                                                                                algorithm: import('../src/options').HashAlgorithm
                                                                                                                                                ) => boolean;

                                                                                                                                                  function isHexadecimal

                                                                                                                                                  isHexadecimal: (str: string) => boolean;

                                                                                                                                                    function isHexColor

                                                                                                                                                    isHexColor: (str: string) => boolean;

                                                                                                                                                      function isHSL

                                                                                                                                                      isHSL: (str: string) => boolean;

                                                                                                                                                        function isIBAN

                                                                                                                                                        isIBAN: (str: string) => boolean;

                                                                                                                                                          function isIdentityCard

                                                                                                                                                          isIdentityCard: (
                                                                                                                                                          str: string,
                                                                                                                                                          locale?: import('../src/options').IdentityCardLocale
                                                                                                                                                          ) => boolean;

                                                                                                                                                            function isIMEI

                                                                                                                                                            isIMEI: (
                                                                                                                                                            str: string,
                                                                                                                                                            options?: import('../src/options').IsIMEIOptions
                                                                                                                                                            ) => boolean;

                                                                                                                                                              function isIn

                                                                                                                                                              isIn: (str: string, values: readonly any[]) => boolean;

                                                                                                                                                                function isInt

                                                                                                                                                                isInt: (str: string, options?: import('../src/options').IsIntOptions) => boolean;

                                                                                                                                                                  function isIP

                                                                                                                                                                  isIP: (str: string, version?: import('../src/options').IPVersion) => boolean;

                                                                                                                                                                    function isIPRange

                                                                                                                                                                    isIPRange: (
                                                                                                                                                                    str: string,
                                                                                                                                                                    version?: import('../src/options').IPVersion
                                                                                                                                                                    ) => boolean;

                                                                                                                                                                      function isISBN

                                                                                                                                                                      isISBN: (str: string, version?: number) => boolean;

                                                                                                                                                                        function isISIN

                                                                                                                                                                        isISIN: (str: string) => boolean;

                                                                                                                                                                          function isISO31661Alpha2

                                                                                                                                                                          isISO31661Alpha2: (str: string) => boolean;

                                                                                                                                                                            function isISO31661Alpha3

                                                                                                                                                                            isISO31661Alpha3: (str: string) => boolean;

                                                                                                                                                                              function isISO8601

                                                                                                                                                                              isISO8601: (
                                                                                                                                                                              str: string,
                                                                                                                                                                              options?: import('../src/options').IsISO8601Options
                                                                                                                                                                              ) => boolean;

                                                                                                                                                                                function isISRC

                                                                                                                                                                                isISRC: (str: string) => boolean;

                                                                                                                                                                                  function isISSN

                                                                                                                                                                                  isISSN: (
                                                                                                                                                                                  str: string,
                                                                                                                                                                                  options?: import('../src/options').IsISSNOptions
                                                                                                                                                                                  ) => boolean;

                                                                                                                                                                                    function isJSON

                                                                                                                                                                                    isJSON: (
                                                                                                                                                                                    str: string,
                                                                                                                                                                                    options?: import('../src/options').IsJSONOptions
                                                                                                                                                                                    ) => boolean;

                                                                                                                                                                                      function isJWT

                                                                                                                                                                                      isJWT: (str: string) => boolean;

                                                                                                                                                                                        function isLatLong

                                                                                                                                                                                        isLatLong: (
                                                                                                                                                                                        str: string,
                                                                                                                                                                                        options?: import('../src/options').IsLatLongOptions
                                                                                                                                                                                        ) => boolean;

                                                                                                                                                                                          function isLength

                                                                                                                                                                                          isLength: (
                                                                                                                                                                                          str: string,
                                                                                                                                                                                          options: import('../src/options').MinMaxOptions
                                                                                                                                                                                          ) => boolean;

                                                                                                                                                                                            function isLicensePlate

                                                                                                                                                                                            isLicensePlate: (
                                                                                                                                                                                            str: string,
                                                                                                                                                                                            locale: import('../src/options').IsLicensePlateLocale
                                                                                                                                                                                            ) => boolean;

                                                                                                                                                                                              function isLocale

                                                                                                                                                                                              isLocale: (str: string) => boolean;

                                                                                                                                                                                                function isLowercase

                                                                                                                                                                                                isLowercase: (str: string) => boolean;

                                                                                                                                                                                                  function isMACAddress

                                                                                                                                                                                                  isMACAddress: (
                                                                                                                                                                                                  str: string,
                                                                                                                                                                                                  options: import('../src/options').IsMACAddressOptions
                                                                                                                                                                                                  ) => boolean;

                                                                                                                                                                                                    function isMagnetURI

                                                                                                                                                                                                    isMagnetURI: (str: string) => boolean;

                                                                                                                                                                                                      function isMD5

                                                                                                                                                                                                      isMD5: (str: string) => boolean;

                                                                                                                                                                                                        function isMimeType

                                                                                                                                                                                                        isMimeType: (str: string) => boolean;

                                                                                                                                                                                                          function isMobilePhone

                                                                                                                                                                                                          isMobilePhone: (
                                                                                                                                                                                                          str: string,
                                                                                                                                                                                                          locale:
                                                                                                                                                                                                          | import('../src/options').MobilePhoneLocale
                                                                                                                                                                                                          | readonly import('../src/options').MobilePhoneLocale[],
                                                                                                                                                                                                          options?: import('../src/options').IsMobilePhoneOptions
                                                                                                                                                                                                          ) => boolean;

                                                                                                                                                                                                            function isMongoId

                                                                                                                                                                                                            isMongoId: (str: string) => boolean;

                                                                                                                                                                                                              function isMultibyte

                                                                                                                                                                                                              isMultibyte: (str: string) => boolean;

                                                                                                                                                                                                                function isNumeric

                                                                                                                                                                                                                isNumeric: (
                                                                                                                                                                                                                str: string,
                                                                                                                                                                                                                options?: import('../src/options').IsNumericOptions
                                                                                                                                                                                                                ) => boolean;

                                                                                                                                                                                                                  function isOctal

                                                                                                                                                                                                                  isOctal: (str: string) => boolean;

                                                                                                                                                                                                                    function isPassportNumber

                                                                                                                                                                                                                    isPassportNumber: (
                                                                                                                                                                                                                    str: string,
                                                                                                                                                                                                                    countryCode?: import('../src/options').PassportCountryCode
                                                                                                                                                                                                                    ) => boolean;

                                                                                                                                                                                                                      function isPort

                                                                                                                                                                                                                      isPort: (str: string) => boolean;

                                                                                                                                                                                                                        function isPostalCode

                                                                                                                                                                                                                        isPostalCode: (
                                                                                                                                                                                                                        str: string,
                                                                                                                                                                                                                        locale: import('../src/options').PostalCodeLocale
                                                                                                                                                                                                                        ) => boolean;

                                                                                                                                                                                                                          function isRFC3339

                                                                                                                                                                                                                          isRFC3339: (str: string) => boolean;

                                                                                                                                                                                                                            function isRgbColor

                                                                                                                                                                                                                            isRgbColor: (str: string, includePercentValues?: boolean) => boolean;

                                                                                                                                                                                                                              function isSemVer

                                                                                                                                                                                                                              isSemVer: (str: string) => boolean;

                                                                                                                                                                                                                                function isSlug

                                                                                                                                                                                                                                isSlug: (str: string) => boolean;

                                                                                                                                                                                                                                  function isStrongPassword

                                                                                                                                                                                                                                  isStrongPassword: (
                                                                                                                                                                                                                                  str: string,
                                                                                                                                                                                                                                  options?: import('../src/options').IsStrongPasswordOptions
                                                                                                                                                                                                                                  ) => boolean;

                                                                                                                                                                                                                                    function isSurrogatePair

                                                                                                                                                                                                                                    isSurrogatePair: (str: string) => boolean;

                                                                                                                                                                                                                                      function isTaxID

                                                                                                                                                                                                                                      isTaxID: (str: string, locale: import('../src/options').TaxIDLocale) => boolean;

                                                                                                                                                                                                                                        function isUppercase

                                                                                                                                                                                                                                        isUppercase: (str: string) => boolean;

                                                                                                                                                                                                                                          function isURL

                                                                                                                                                                                                                                          isURL: (str: string, options?: import('../src/options').IsURLOptions) => boolean;

                                                                                                                                                                                                                                            function isUUID

                                                                                                                                                                                                                                            isUUID: (str: string, version?: import('../src/options').UUIDVersion) => boolean;

                                                                                                                                                                                                                                              function isVariableWidth

                                                                                                                                                                                                                                              isVariableWidth: (str: string) => boolean;

                                                                                                                                                                                                                                                function isVAT

                                                                                                                                                                                                                                                isVAT: (
                                                                                                                                                                                                                                                str: string,
                                                                                                                                                                                                                                                countryCode: import('../src/options').VATCountryCode
                                                                                                                                                                                                                                                ) => boolean;

                                                                                                                                                                                                                                                  function isWhitelisted

                                                                                                                                                                                                                                                  isWhitelisted: (str: string, chars: string | readonly string[]) => boolean;

                                                                                                                                                                                                                                                    function ltrim

                                                                                                                                                                                                                                                    ltrim: (str: string, chars?: string) => string;

                                                                                                                                                                                                                                                      function matches

                                                                                                                                                                                                                                                      matches: (str: string, pattern: RegExp | string, modifiers?: string) => boolean;

                                                                                                                                                                                                                                                        function normalizeEmail

                                                                                                                                                                                                                                                        normalizeEmail: (
                                                                                                                                                                                                                                                        str: string,
                                                                                                                                                                                                                                                        options?: import('../src/options').NormalizeEmailOptions
                                                                                                                                                                                                                                                        ) => string;

                                                                                                                                                                                                                                                          function rtrim

                                                                                                                                                                                                                                                          rtrim: (str: string, chars?: string) => string;

                                                                                                                                                                                                                                                            function stripLow

                                                                                                                                                                                                                                                            stripLow: (str: string, keep_new_lines?: boolean) => string;

                                                                                                                                                                                                                                                              function toBoolean

                                                                                                                                                                                                                                                              toBoolean: (str: string, strict?: boolean) => boolean;

                                                                                                                                                                                                                                                                function toDate

                                                                                                                                                                                                                                                                toDate: (str: string) => Date;

                                                                                                                                                                                                                                                                  function toFloat

                                                                                                                                                                                                                                                                  toFloat: (str: string) => number;

                                                                                                                                                                                                                                                                    function toInt

                                                                                                                                                                                                                                                                    toInt: (str: string, radix?: number) => string;

                                                                                                                                                                                                                                                                      function toString

                                                                                                                                                                                                                                                                      toString: (str: string) => string;

                                                                                                                                                                                                                                                                        function trim

                                                                                                                                                                                                                                                                        trim: (str: string, chars?: string) => string;

                                                                                                                                                                                                                                                                          function unescape

                                                                                                                                                                                                                                                                          unescape: (str: string) => string;

                                                                                                                                                                                                                                                                            function whitelist

                                                                                                                                                                                                                                                                            whitelist: (str: string, chars: string) => string;

                                                                                                                                                                                                                                                                              Package Files (11)

                                                                                                                                                                                                                                                                              Dependencies (2)

                                                                                                                                                                                                                                                                              Dev Dependencies (13)

                                                                                                                                                                                                                                                                              Peer Dependencies (0)

                                                                                                                                                                                                                                                                              No peer dependencies.

                                                                                                                                                                                                                                                                              Badge

                                                                                                                                                                                                                                                                              To add a badge like this onejsDocs.io badgeto your package's README, use the codes available below.

                                                                                                                                                                                                                                                                              You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/express-validator.

                                                                                                                                                                                                                                                                              • Markdown
                                                                                                                                                                                                                                                                                [![jsDocs.io](https://img.shields.io/badge/jsDocs.io-reference-blue)](https://www.jsdocs.io/package/express-validator)
                                                                                                                                                                                                                                                                              • HTML
                                                                                                                                                                                                                                                                                <a href="https://www.jsdocs.io/package/express-validator"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>