Values to be whitelisted.
The string doesn't only contain alphanumeric characters.
The string is not a valid credit card number.
Allows specify schemas directly via Joi's schema api.
Sets a default value.
the value.
Annotates the key
Blacklists values for this property.
Values to be blacklisted.
Specifies that value must be a valid e-mail.
Considers anything that matches the schema to be empty (undefined).
any object or joi schema to match. An undefined schema unsets that rule.
Adds the provided values into the allowed whitelist for property and marks them as the only valid values allowed.
The only valid values this property can accept.
Overrides the default joi error with a custom error if the rule fails where:
can be:
an instance of Error
- the override error.
a function (errors)
, taking an array of errors as argument, where it must either:
return a string
- substitutes the error message with this text
return a single object
or an Array
of it, where:
type
- optional parameter providing the type of the error (eg. number.min
).
message
- optional parameter if template
is provided, containing the text of the error.
template
- optional parameter if message
is provided, containing a template string,
using the same format as usual joi language errors.
context
- optional parameter, to provide context to your error if you are using the template
.
return an Error
- same as when you directly provide an Error
,
but you can customize the error message based on the errors.
Note that if you provide an Error
, it will be returned as-is, unmodified and undecorated with any of the
normal joi error properties. If validation fails and another error is found before the error
override, that error will be returned and the override will be ignored (unless the abortEarly
option has been set to false
).
Specifies the exact string length required.
The required string length.
If specified, the string length is calculated in bytes using the provided encoding.
Annotates the key with an example value, must be valid.
Marks a key as forbidden which will not allow any value except undefined. Used to explicitly forbid keys.
Requires the string value to be a valid GUID.
Optional. options.version specifies one or more acceptable versions. Can be an array or string with the following values: uuidv1, uuidv2, uuidv3, uuidv4, or uuidv5. If no version is specified then it is assumed to be a generic guid which will not validate the version or variant of the guid and just check for general structure format.
Requires the string value to be a valid hexadecimal string.
Requires the string value to be a valid hostname as per RFC1123.
Allows the value to match any value in the allowed list or disallowed list in a case insensitive comparison.
e.g. @jf.string().valid('a').insensitive()
Blacklists values for this property.
Values to be blacklisted.
Requires the string value to be a valid ip address.
optional settings: version - One or more IP address versions to validate against. Valid values: ipv4, ipv6, ipvfuture cidr - Used to determine if a CIDR is allowed or not. Valid values: optional, required, forbidden
Requires the string value to be in valid ISO 8601 date format. If the validation convert option is on (enabled by default), the string will be forced to simplified extended ISO format (ISO 8601). Be aware that this operation uses javascript Date object, which does not support the full ISO format, so a few formats might not pass when using convert.
Overrides the key name in error messages.
The label to use.
Specifies that the string must be in lowercase.
Specifies the maximum length.
The maximum length.
Attaches metadata to the key.
Specifies the minimum length.
The minimum length.
Blacklists values for this property.
Values to be blacklisted.
Annotates the key
Adds the provided values into the allowed whitelist for property and marks them as the only valid values allowed.
Marks a key as optional which will allow undefined as values. Used to annotate the schema for readability as all keys are optional by default.
Overrides the global validate() options for the current key and any sub-key.
Defines a pattern rule.
A regular expression object the string value must match against.
Optional name for patterns (useful with multiple patterns).
Outputs the original untouched value instead of the casted value.
Defines a pattern rule.
A regular expression object the string value must match against.
Optional name for patterns (useful with multiple patterns).
Replace characters matching the given pattern with the specified replacement string.
A regular expression object to match against, or a string of which all occurrences will be replaced.
The string that will replace the pattern.
Marks a key as required which will not allow undefined as value. All keys are optional by default.
Sets the options.convert options to false which prevent type casting for the current key and any child keys.
Marks a key to be removed from a resulting object or array after validation. Used to sanitize output.
Annotates the key
Requires the string value to only contain a-z, A-Z, 0-9, and underscore _.
Requires the string value to contain no whitespace before or after. If the validation convert option is on (enabled by default), the string will be trimmed.
Annotates the key with an unit name.
Specifies that the string must be in uppercase.
Requires the string value to be a valid RFC 3986 URI.
Optional settings: scheme - Specifies one or more acceptable Schemes, should only include the scheme name. Can be an Array or String (strings are automatically escaped for use in a Regular Expression). allowRelative - Allow relative URIs. Defaults to false. relativeOnly - Restrict only relative URIs. Defaults to false. allowQuerySquareBrackets - Allows unencoded square brackets inside the query string. This is NOT RFC 3986 compliant but query strings like abc[]=123&abc[]=456 are very common these days. Defaults to false. domain - Validate the domain component using the options specified in string.domain().
Adds the provided values into the allowed whitelist for property and marks them as the only valid values allowed.
The only valid values this property can accept.
Generated using TypeDoc
Whitelists values. Note that this list of allowed values is in addition to any other permitted values. To create an exclusive list of values, use the
Valid
decorator.