DefinitelyTyped

Index

Dynamic modules

Functions

Functions

ExpressValidator()

RequestValidation: RequestValidation

public assert(field: string, message: string): Validator

Parameters

  • field: string
  • message: string

Returns

Validator

public check(field: string, message: string): Validator

Parameters

  • field: string
  • message: string

Returns

Validator

public onValidationError(func: (msg: string) => void)

Parameters

  • func: (msg: string) => void

public sanitize(field: string): Sanitizer

Parameters

  • field: string

Returns

Sanitizer

Sanitizer: Sanitizer

public entityDecode(): Sanitizer

Decode HTML entities

Returns

Sanitizer

public entityEncode(): Sanitizer

Returns

Sanitizer

public escape(): Sanitizer

Escape &, <, >, and "

Returns

Sanitizer

public ifNull(replace: any): Sanitizer

Parameters

  • replace: any

Returns

Sanitizer

public ltrim(chars?: Array<string>): Sanitizer

Parameters

  • chars?: Array<string> optional

Returns

Sanitizer

public rtrim(chars?: Array<string>): Sanitizer

Parameters

  • chars?: Array<string> optional

Returns

Sanitizer

public toBoolean(): Sanitizer

True unless str = '0', 'false', or str.length == 0

Returns

Sanitizer

public toBooleanStrict(): Sanitizer

False unless str = '1' or 'true'

Returns

Sanitizer

public toFloat(): Sanitizer

Returns

Sanitizer

public toInt(): Sanitizer

Returns

Sanitizer

public trim(chars?: Array<string>): Sanitizer

Trim optional chars, default is to trim whitespace (\r\n\t )

Parameters

  • chars?: Array<string> optional

Returns

Sanitizer

public xss(): Sanitizer

Remove common XSS attack vectors from user-supplied HTML

Returns

Sanitizer

public xss(fromImages: boolean): Sanitizer

Remove common XSS attack vectors from images

Parameters

  • fromImages: boolean

Returns

Sanitizer

ValidationError: ValidationError

public msg: string

public param: string

Validator: Validator

public contains(str: string): Validator

Parameters

  • str: string

Returns

Validator

public equals(equals: any): Validator

Parameters

  • equals: any

Returns

Validator

public is(): Validator

Alias for regex()

Returns

Validator

public isAfter(date: Date): Validator

Argument is optional and defaults to today. Comparison is non-inclusive

Parameters

  • date: Date

Returns

Validator

public isAlpha(): Validator

Returns

Validator

public isAlphanumeric(): Validator

Returns

Validator

public isBefore(date: Date): Validator

Argument is optional and defaults to today. Comparison is non-inclusive

Parameters

  • date: Date

Returns

Validator

public isCreditCard(): Validator

Will work against Visa, MasterCard, American Express, Discover, Diners Club, and JCB card numbering formats

Returns

Validator

public isDate(): Validator

Uses Date.parse() - regex is probably a better choice

Returns

Validator

public isDecimal(): Validator

Returns

Validator

public isEmail(): Validator

Returns

Validator

public isFloat(): Validator

Alias for isDecimal

Returns

Validator

public isHexColor(): Validator

Accepts valid hexcolors with or without # prefix

Returns

Validator

public isHexadecimal(): Validator

Returns

Validator

public isIP(): Validator

Combines isIPv4 and isIPv6

Returns

Validator

public isIPv4(): Validator

Returns

Validator

public isIPv6(): Validator

Returns

Validator

public isIn(options: string): Validator

Parameters

  • options: string

Returns

Validator

public isIn(options: Array<string>): Validator

Parameters

  • options: Array<string>

Returns

Validator

public isInt(): Validator

isNumeric accepts zero padded numbers, e.g. '001', isInt doesn't

Returns

Validator

public isLowercase(): Validator

Returns

Validator

public isNull(): Validator

Returns

Validator

public isNumeric(): Validator

Returns

Validator

public isUUID(version: number): Validator

Version can be 3, 4 or 5 or empty, see http://en.wikipedia.org/wiki/Universally_unique_identifier

Parameters

  • version: number

Returns

Validator

public isUUIDv3(): Validator

Alias for isUUID(3)

Returns

Validator

public isUUIDv4(): Validator

Alias for isUUID(4)

Returns

Validator

public isUUIDv5(): Validator

Alias for isUUID(5)

Returns

Validator

public isUppercase(): Validator

Returns

Validator

public isUrl(): Validator

Accepts http, https, ftp

Returns

Validator

public len(min: number, max?: number): Validator

max is optional

Parameters

  • min: number
  • max?: number optional

Returns

Validator

public max(val: string): Validator

Parameters

  • val: string

Returns

Validator

public min(val: string): Validator

Parameters

  • val: string

Returns

Validator

public not(): Validator

Alias for notRegex()

Returns

Validator

public notContains(str: string): Validator

Parameters

  • str: string

Returns

Validator

public notEmpty(): Validator

Not just whitespace (input.trim().length !== 0)

Returns

Validator

public notIn(options: string): Validator

Parameters

  • options: string

Returns

Validator

public notIn(options: Array<string>): Validator

Parameters

  • options: Array<string>

Returns

Validator

public notNull(): Validator

Check if length is 0

Returns

Validator

public notRegex(pattern: string, modifiers: string): Validator

Parameters

  • pattern: string
  • modifiers: string

Returns

Validator

public regex(pattern: string, modifiers: string): Validator

Usage: regex(/[a-z]/i) or regex('[a-z]','i')

Parameters

  • pattern: string
  • modifiers: string

Returns

Validator