Documentation
    Preparing search index...

    Interface ColumnValidateOptions

    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.

    interface ColumnValidateOptions {
        contains?: string | { msg: string };
        equals?: string | { msg: string };
        is?:
            | string
            | RegExp
            | readonly (string | RegExp)[]
            | { args: string | RegExp | readonly (string | RegExp)[]; msg: string };
        isAfter?: string | { args: string; msg: string };
        isAlpha?: boolean | { msg: string };
        isAlphanumeric?: boolean | { msg: string };
        isArray?: boolean | { args: boolean; msg: string };
        isBefore?: string | { args: string; msg: string };
        isCreditCard?: boolean | { args: boolean; msg: string };
        isDate?: boolean | { args: boolean; msg: string };
        isDecimal?: boolean | { msg: string };
        isEmail?: boolean | { msg: string };
        isFloat?: boolean | { msg: string };
        isIn?:
            | readonly (readonly any[])[]
            | { args: readonly (readonly any[])[]; msg: string };
        isInt?: boolean | { msg: string };
        isIP?: boolean | { msg: string };
        isIPv4?: boolean | { msg: string };
        isIPv6?: boolean | { msg: string };
        isLowercase?: boolean | { msg: string };
        isNull?: boolean | { msg: string };
        isNumeric?: boolean | { msg: string };
        isUppercase?: boolean | { msg: string };
        isUrl?: boolean | { msg: string };
        isUUID?: UUIDVersion | { args: UUIDVersion; msg: string };
        len?:
            | readonly [number, number]
            | { args: readonly [number, number]; msg: string };
        max?: number | { args: readonly [number]; msg: string };
        min?: number | { args: readonly [number]; msg: string };
        not?:
            | string
            | RegExp
            | readonly (string | RegExp)[]
            | { args: string | RegExp | readonly (string | RegExp)[]; msg: string };
        notContains?:
            | string
            | readonly string[]
            | { args: string
            | readonly string[]; msg: string };
        notEmpty?: boolean | { msg: string };
        notIn?:
            | readonly (readonly any[])[]
            | { args: readonly (readonly any[])[]; msg: string };
        notNull?: boolean | { msg: string };
        [name: string]: unknown;
    }

    Indexable

    • [name: string]: unknown

      Custom validations are also possible

    Index
    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

    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

    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

    isLowercase?: boolean | { msg: string }

    checks for lowercase

    isNull?: boolean | { msg: string }

    only allows null

    isNumeric?: boolean | { msg: string }

    will only allow numbers

    isUppercase?: boolean | { msg: string }

    checks for uppercase

    isUrl?: boolean | { msg: string }

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

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

    only allow uuids

    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