Options
All
  • Public
  • Public/Protected
  • All
Menu

These are the validation functions for the runtime-data-validation package. These functions all take as their first parameter a value, as a string, that is to be validated. Any additional parameters provide configuration to customize the validation.

These functions can serve as type guard functions. In other words, at the beginning of a function it is good form to validate the parameters. If your function is part of a class its parameters can be validated using decorators. But a standalone function cannot be instrumented with decorators, in which case you can directly use these functions.

USAGE:

import { validators } from 'runtime-data-validation';

function operation(value: string) {
if (!validators.isAscii(value)) {
throw new Error(`Invalid value ${value}`);
}
// Continue with code
}

Return to home page

Index

Options

ContainsOptions: { ignoreCase?: boolean; minOccurrences?: number }

Type declaration

  • Optional ignoreCase?: boolean
  • Optional minOccurrences?: number
IsAlphaOptions: { ignore?: string | RegExp }

Type declaration

  • Optional ignore?: string | RegExp
IsBase64Options: { urlSafe?: boolean }

Type declaration

  • Optional urlSafe?: boolean
IsBooleanOptions: { loose?: boolean }

Type declaration

  • Optional loose?: boolean
IsByteLengthOptions: { max: number; min: number }

Type declaration

  • max: number
  • min: number
IsDateOptions: { delimiters?: string[]; format?: string; strictMode?: boolean }

Type declaration

  • Optional delimiters?: string[]
  • Optional format?: string
  • Optional strictMode?: boolean
IsDecimalOptions: { decimal_digits?: string; force_decimal?: boolean; locale?: string }

Type declaration

  • Optional decimal_digits?: string
  • Optional force_decimal?: boolean
  • Optional locale?: string
IsEmailOptions: { allow_display_name?: boolean; allow_ip_domain?: boolean; allow_utf8_local_part?: boolean; blacklisted_chars?: string; domain_specific_validation?: boolean; host_blacklist?: string[]; require_display_name?: boolean; require_tld?: boolean }

Type declaration

  • Optional allow_display_name?: boolean
  • Optional allow_ip_domain?: boolean
  • Optional allow_utf8_local_part?: boolean
  • Optional blacklisted_chars?: string
  • Optional domain_specific_validation?: boolean
  • Optional host_blacklist?: string[]
  • Optional require_display_name?: boolean
  • Optional require_tld?: boolean
IsEmptyOptions: { ignore_whitespace?: boolean }

Type declaration

  • Optional ignore_whitespace?: boolean
IsFQDNOptions: { allow_numeric_tld?: boolean; allow_trailing_dot?: boolean; allow_underscores?: boolean; allow_wildcard?: boolean; require_tld?: boolean }

Type declaration

  • Optional allow_numeric_tld?: boolean
  • Optional allow_trailing_dot?: boolean
  • Optional allow_underscores?: boolean
  • Optional allow_wildcard?: boolean
  • Optional require_tld?: boolean
IsFloatOptions: { locale?: string; max?: number; min?: number }

Type declaration

  • Optional locale?: string
  • Optional max?: number
  • Optional min?: number
IsIMEIOptions: { allow_hyphens?: boolean }

Type declaration

  • Optional allow_hyphens?: boolean
IsISO8601Options: { strict?: boolean; strictSeparator?: boolean }

Type declaration

  • Optional strict?: boolean
  • Optional strictSeparator?: boolean
IsIntOptions: { allow_leading_zeros?: boolean; max?: number; min?: number }

Type declaration

  • Optional allow_leading_zeros?: boolean
  • Optional max?: number
  • Optional min?: number
isJSONOptions: { allow_primitives: boolean }

Type declaration

  • allow_primitives: boolean
isLatLongOptions: { checkDMS: boolean }

Type declaration

  • checkDMS: boolean
isLengthOptions: { max?: number; min?: number }

Type declaration

  • Optional max?: number
  • Optional min?: number
isMACAddressOptions: { eui?: string; no_separators?: boolean }

Type declaration

  • Optional eui?: string
  • Optional no_separators?: boolean
isMobilePhoneOptions: { strictMode?: boolean }

Type declaration

  • Optional strictMode?: boolean
isNumericOptions: { no_symbols?: boolean }

Type declaration

  • Optional no_symbols?: boolean
isStrongPasswordOptions: { minLength?: number; minLowercase?: number; minNumbers?: number; minSymbols?: number; minUppercase?: number; pointsForContainingLower?: number; pointsForContainingNumber?: number; pointsForContainingSymbol?: number; pointsForContainingUpper?: number; pointsPerRepeat?: number; pointsPerUnique?: number; returnScore?: boolean }

Type declaration

  • Optional minLength?: number
  • Optional minLowercase?: number
  • Optional minNumbers?: number
  • Optional minSymbols?: number
  • Optional minUppercase?: number
  • Optional pointsForContainingLower?: number
  • Optional pointsForContainingNumber?: number
  • Optional pointsForContainingSymbol?: number
  • Optional pointsForContainingUpper?: number
  • Optional pointsPerRepeat?: number
  • Optional pointsPerUnique?: number
  • Optional returnScore?: boolean
isURLOptions: { allow_fragments?: boolean; allow_protocol_relative_urls?: boolean; allow_query_components?: boolean; allow_trailing_dot?: boolean; allow_underscores?: boolean; disallow_auth?: boolean; host_blacklist?: boolean; host_whitelist?: boolean; protocols?: string[]; require_host?: boolean; require_port?: boolean; require_protocol?: boolean; require_tld?: boolean; require_valid_protocol?: boolean; validate_length?: boolean }

Type declaration

  • Optional allow_fragments?: boolean
  • Optional allow_protocol_relative_urls?: boolean
  • Optional allow_query_components?: boolean
  • Optional allow_trailing_dot?: boolean
  • Optional allow_underscores?: boolean
  • Optional disallow_auth?: boolean
  • Optional host_blacklist?: boolean
  • Optional host_whitelist?: boolean
  • Optional protocols?: string[]
  • Optional require_host?: boolean
  • Optional require_port?: boolean
  • Optional require_protocol?: boolean
  • Optional require_tld?: boolean
  • Optional require_valid_protocol?: boolean
  • Optional validate_length?: boolean
isMobilePhoneLocales: any = validator.isMobilePhoneLocales
isPostalCodeLocales: any = validator.isPostalCodeLocales

Date Validator

isRFC3339: any = validator.isRFC3339

check if the string is a valid RFC 3339 date. https://tools.ietf.org/html/rfc3339

param value

The string to validate

returns
  • isISO8601Duration(value: string): boolean
  • Check if the input is a valid ISO8601 Duration string. For a discussion of this format see https://en.wikipedia.org/wiki/ISO_8601#Durations For example, "P3Y6M4DT12H30M5S" represents a duration of "three years, six months, four days, twelve hours, thirty minutes, and five seconds".

    Parameters

    • value: string

      The string to validate

    Returns boolean

Finance Validator

isBtcAddress: any = validator.isBtcAddress

Check if the string is a valid BTC address.

param value

The string to validate

returns
isCreditCard: any = validator.isCreditCard
param value

The string to validate

returns
isEthereumAddress: any = validator.isEthereumAddress

Check if the string is an Ethereum address using basic regex. Does not validate address checksums.

param value
returns
isISO4217: any = validator.isISO4217

Check if the string is a valid ISO 4217 officially assigned currency code.

param value
returns
  • isTaxID(value: any, locale?: string): any
  • Check if the given value is a valid Tax Identification Number. For precise info about exact TIN support, consult the parent validator.js package source code.

    Parameters

    • value: any
    • Optional locale: string

    Returns any

Internet Validator

isDataURI: any = validator.isDataURI
param value

The string to validate

returns
isHSL: any = validator.isHSL
param value
returns
isHexColor: any = validator.isHexColor
param value
returns
isHexadecimal: any = validator.isHexadecimal
param value
returns
isISO31661Alpha2: any = validator.isISO31661Alpha2

Check if the string is a valid ISO 3166-1 alpha-2 officially assigned country code.

param value

The string to validate

returns
isISO31661Alpha3: any = validator.isISO31661Alpha3

Check if the string is a valid ISO 3166-1 alpha-3 officially assigned country code.

param value

The string to validate

returns
isISRC: any = validator.isISRC

Check if the string is an International Standard Recording Code (ISRC). https://en.wikipedia.org/wiki/International_Standard_Recording_Code

param value

The string to validate

returns
isJWT: any = validator.isJWT

Check if the string is valid JWT token.

param value

The string to validate

returns
isMD5: any = validator.isMD5

check if the string is a MD5 hash. Equivalent to isHash(value, 'md5').

param value

The string to validate

returns
isMagnetURI: any = validator.isMagnetURI

check if the string is a magnet uri format. https://en.wikipedia.org/wiki/Magnet_URI_scheme

param value

The string to validate

returns
isMimeType: any = validator.isMimeType

check if the string matches to a valid MIME type format https://en.wikipedia.org/wiki/Media_type

param value

The string to validate

returns
isPort: any = validator.isPort

check if the string is a valid port number.

param value

The string to validate

returns
isSlug: any = validator.isSlug

Check if the string is of type slug. Options allow a single hyphen between string. e.g. [cn-cn, cn-c-c]

param value

The string to validate

returns
  • isHash(value: string, algorithm: string): any
  • check if the string is a hash of type algorithm.

    Parameters

    • value: string
    • algorithm: string

    Returns any

  • isIP(value: string, version?: number): any
  • isIPRange(value: string, version?: number): any
  • isRgbColor(value: string, includePercentValues?: boolean): any
  • check if the string is a rgb or rgba color.

    Parameters

    • value: string

      The string to validate

    • Optional includePercentValues: boolean

    Returns any

  • isUUID(value: string, version?: string | number): any
  • check if the string is a UUID (version 1, 2, 3, 4 or 5).

    Parameters

    • value: string

      The string to validate

    • Optional version: string | number

    Returns any

Numerical Validator

isOctal: any = validator.isOctal

check if the string is a valid octal number.

param value
returns
  • isFloatRange(value: string | number, min: number, max: number): boolean
  • isInt(value: string | number, options?: IsIntOptions): boolean
  • isIntRange(value: string | number, min: number, max: number): boolean

Other

Renames and re-exports blacklist
Renames and re-exports blacklist
Renames and re-exports blacklist
Renames and re-exports blacklist
Renames and re-exports blacklist
Renames and re-exports blacklist
Renames and re-exports blacklist
Renames and re-exports blacklist
Renames and re-exports blacklist
Renames and re-exports blacklist
Renames and re-exports blacklist
Renames and re-exports blacklist
isISSNOptions: { case_sensitive?: boolean; require_hyphen?: boolean }

Type declaration

  • Optional case_sensitive?: boolean
  • Optional require_hyphen?: boolean
blacklist: any

Publications Validator

isEAN: any = validator.isEAN
param value
returns
  • isISBN(value: string, version?: number): any

String Validator

isAscii: any = validator.isAscii
param value
returns
isBase32: any = validator.isBase32
param value
returns
isBase58: any = validator.isBase58
param value
returns
isFullWidth: any = validator.isFullWidth
param value
returns
isHalfWidth: any = validator.isHalfWidth
param value
returns
isLowercase: any = validator.isLowercase

check if the string is lowercase.

param value
returns
isMultibyte: any = validator.isMultibyte

check if the string contains one or more multibyte chars.

param value
returns
isSurrogatePair: any = validator.isSurrogatePair

check if the string contains any surrogate pairs chars.

param value
returns
isUppercase: any = validator.isUppercase

check if the string is uppercase.

param value
returns
isVariableWidth: any = validator.isVariableWidth

check if the string contains a mixture of full and half-width chars.

param value
returns
  • equals(value: string, comparison: string): boolean
  • isAlpha(value: string, locale?: string, options?: IsAlphaOptions): boolean
  • isAlphanumeric(value: string, locale?: string, options?: IsAlphaOptions): boolean
  • isIn(value: string, values: string[]): boolean
  • isWhitelisted(value: string, chars: string): any
  • checks characters if they appear in the whitelist.

    Parameters

    • value: string
    • chars: string

    Returns any

  • matches(value: string, pattern: string | RegExp, modifiers?: string): any
  • check if string matches the pattern.

    Either matches('foo', /foo/i) or matches('foo', 'foo', 'i').

    Parameters

    • value: string
    • pattern: string | RegExp
    • Optional modifiers: string

    Returns any

Validator

isIBAN: any = validator.isIBAN
param value
returns
isISIN: any = validator.isISIN

check if the string is an ISIN (stock/security identifier).

param value
returns
isLocale: any = validator.isLocale

check if the string is a locale

param value
param locale
param options
returns
isMongoId: any = validator.isMongoId

check if the string is a valid hex-encoded representation of a MongoDB ObjectId. http://docs.mongodb.org/manual/reference/object-id/

param value
returns
isSemVer: any = validator.isSemVer

check if the string is a Semantic Versioning Specification (SemVer).

param value
returns
  • isIdentityCard(value: string, locale?: string): any
  • check if the string is a valid latitude-longitude coordinate in the format lat,long or lat, long.

    Parameters

    Returns any

  • isLicensePlate(value: string, locale?: string): any
  • check if string matches the format of a country's license plate.

    Parameters

    • value: string
    • Optional locale: string

    Returns any

  • isPassportNumber(value: any, countryCode?: string): any
  • check if the string is a valid passport number.

    Parameters

    • value: any
    • Optional countryCode: string

    Returns any

  • isPostalCode(value: any, locale?: string): any
  • check if the string is a postal code,

    Parameters

    • value: any
    • Optional locale: string

    Returns any

  • Check if a password is strong or not. Allows for custom requirements or scoring rules. If returnScore is true, then the function returns an integer score for the password rather than a boolean.

    Parameters

    Returns any

  • isVAT(value: any, countryCode: string): any