diff --git a/types/joi/index.d.ts b/types/joi/index.d.ts index 94ffd188cf..7838323e6b 100644 --- a/types/joi/index.d.ts +++ b/types/joi/index.d.ts @@ -164,6 +164,11 @@ export interface IPOptions { cidr?: string } +export interface StringRegexOptions { + name?: string; + invert?: boolean; +} + export interface JoiObject { isJoi: boolean; } @@ -551,9 +556,13 @@ export interface StringSchema extends AnySchema { /** * Defines a regular expression rule. * @param pattern - a regular expression object the string value must match against. - * @param name - optional name for patterns (useful with multiple patterns). Defaults to 'required'. + * @param options - optional, can be: + * Name for patterns (useful with multiple patterns). Defaults to 'required'. + * An optional configuration object with the following supported properties: + * name - optional pattern name. + * invert - optional boolean flag. Defaults to false behavior. If specified as true, the provided pattern will be disallowed instead of required. */ - regex(pattern: RegExp, name?: string): this; + regex(pattern: RegExp, options?: string | StringRegexOptions): this; /** * Replace characters matching the given pattern with the specified replacement string where: diff --git a/types/joi/joi-tests.ts b/types/joi/joi-tests.ts index 3ee7c45b66..1ab3316eb8 100644 --- a/types/joi/joi-tests.ts +++ b/types/joi/joi-tests.ts @@ -135,6 +135,13 @@ refOpts = { contextPrefix: str }; // --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- +let stringRegexOpts: Joi.StringRegexOptions = null; + +stringRegexOpts = { name: str }; +stringRegexOpts = { invert: bool }; + +// --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- + let validErr: Joi.ValidationError = null; let validErrItem: Joi.ValidationErrorItem; let validErrFunc: Joi.ValidationErrorFunction; @@ -764,6 +771,7 @@ strSchema = strSchema.length(ref); strSchema = strSchema.length(ref, str); strSchema = strSchema.regex(exp); strSchema = strSchema.regex(exp, str); +strSchema = strSchema.regex(exp, stringRegexOpts); strSchema = strSchema.replace(exp, str); strSchema = strSchema.replace(str, str); strSchema = strSchema.alphanum();