Interface ModelValidateOptions

Model validations, allow you to specify format/content/inheritance validations for each attribute of the model.

Validations are automatically run on create, update and save. You can also call validate() to manually validate an instance.

The validations are implemented by validator.js.

Hierarchy

  • ModelValidateOptions

Indexable

[name: string]: unknown

Properties

contains?: string | {
    msg: string;
}

force specific substrings

equals?: string | {
    msg: string;
}

only allow a specific value

is?: string | RegExp | readonly (string | RegExp)[] | {
    args: string | RegExp | readonly (string | RegExp)[];
    msg: string;
}
  • { is: ['^[a-z]+$','i'] } will only allow letters
  • { is: /^[a-z]+$/i } also only allows letters
isAfter?: string | {
    args: string;
    msg: string;
}

only allow date strings after a specific date

isAlpha?: boolean | {
    msg: string;
}

will only allow letters

isAlphanumeric?: boolean | {
    msg: string;
}

will only allow alphanumeric characters, so "_abc" will fail

isArray?: boolean | {
    args: boolean;
    msg: string;
}

only allow arrays

isBefore?: string | {
    args: string;
    msg: string;
}

only allow date strings before a specific date

isCreditCard?: boolean | {
    args: boolean;
    msg: string;
}

check for valid credit card numbers

isDate?: boolean | {
    args: boolean;
    msg: string;
}

only allow date strings

isDecimal?: boolean | {
    msg: string;
}

checks for any numbers

isEmail?: boolean | {
    msg: string;
}

checks for email format (foo@bar.com)

isFloat?: boolean | {
    msg: string;
}

checks for valid floating point numbers

isIP?: boolean | {
    msg: string;
}

checks for IPv4 (129.89.23.1) or IPv6 format

isIPv4?: boolean | {
    msg: string;
}

checks for IPv4 (129.89.23.1)

isIPv6?: boolean | {
    msg: string;
}

checks for IPv6 format

isIn?: readonly (readonly any[])[] | {
    args: readonly (readonly any[])[];
    msg: string;
}

check the value is one of these

isInt?: boolean | {
    msg: string;
}

checks for valid integers

isLowercase?: boolean | {
    msg: string;
}

checks for lowercase

isNull?: boolean | {
    msg: string;
}

only allows null

isNumeric?: boolean | {
    msg: string;
}

will only allow numbers

isUUID?: number | {
    args: number;
    msg: string;
}

only allow uuids

isUppercase?: boolean | {
    msg: string;
}

checks for uppercase

isUrl?: boolean | {
    msg: string;
}

checks for url format (http://foo.com)

len?: readonly [number, number] | {
    args: readonly [number, number];
    msg: string;
}

only allow values with length between 2 and 10

max?: number | {
    args: readonly [number];
    msg: string;
}

only allow values

min?: number | {
    args: readonly [number];
    msg: string;
}

only allow values >= 23

not?: string | RegExp | readonly (string | RegExp)[] | {
    args: string | RegExp | readonly (string | RegExp)[];
    msg: string;
}
  • { not: ['[a-z]','i'] } will not allow letters
notContains?: string | readonly string[] | {
    args: string | readonly string[];
    msg: string;
}

don't allow specific substrings

notEmpty?: boolean | {
    msg: string;
}

don't allow empty strings

notIn?: readonly (readonly any[])[] | {
    args: readonly (readonly any[])[];
    msg: string;
}

check the value is not one of these

notNull?: boolean | {
    msg: string;
}

won't allow null

Generated using TypeDoc