Validators
#
OptionsAll validators accept as their final argument the same set of options (optional):
#
nameBy default, name
is the name
of the validator you are calling - i.e. the name for the oneOf validator is oneOf
.
#
paramsparams
differ from validator to validator and are provided to the string/message function for convenience. label
is the only common parameter always available for interpolation. For more information about error messages see error messages.
#
messagemessage
is a string or a function used to define the error message for this specific validator. If a string the appropriate parameters will be interpolated using ${interpolationparam}
.
- ast
- functional
#
ValidatorsValidators aren't always applicable to all schemas (min is not relevant for a boolean schema, for instance) This is accomplished via a pre-validation hook which verifies that the current ValidatorDefinition is applicable to the current schema.
Note: undefined
is considered a valid value for all validators except required.
#
requiredrequired(options: ValidatorOptions)
Applicable to schemas: ALL
Most of the time undefined
is not validated. This is accomplished via the pre-validation check
function that determines if a validator is applicable given a schema type/value.
required
does validate the value of undefined
and it returns false if the value being validated is undefined
or null
.
In the case of an array, it also requires at least 1 element and in the case of a string it requires the string be non-empty (not ""
).
- ast
- functional
#
isis(value: any | Ref, options: ValidatorOptions)
Applicable to schemas: ALL
Value being validated must equal (===
) the value/ref.
Note: This validator is equivalent to oneOf([value: any | Ref]), except the ValidationError type
is is
.
- ast
- functional
#
notnot(value: any | Ref, options: ValidatorOptions)
Applicable to schemas: ALL
- ast
- functional
#
oneOfoneOf(value: Ref | Array<any | Ref>, options: ValidatorOptions)
Applicable to schemas: ALL
Value being validated must be one of the values given to oneOf
OR if value
is a ref then the value being validated must be one of the values in the reference.
Note: Just a reminder that undefined
is considered a valid value. If you need to test for undefined
use required.
- ast
- functional
#
notOneOfnotOneOf(value: Array<any | Ref>, options: ValidatorOptions)
Applicable to schemas: ALL
- ast
- functional
#
samesame(value: string, options: ValidatorOptions)
Applicable to schemas: ALL
Validation-sugar for is(ref(value))
.
- ast
- functional
#
differentdifferent(value: string, options: ValidatorOptions)
Applicable to schemas: ALL
- ast
- functional
#
matchesmatches(value: string | RegExp | Array<string | RegExp>, options = { validateEmpty: boolean, ...ValidatorOptions })
Applicable to schemas: STRING
Validates that the value being validated matches the provided string/regexp. In the case of an array, the value being validated must match one of the provided string/regexp.
Empty strings always return true unless validateEmpty: true
is passed as an option.
- ast
- functional
#
emailemail(options = { validateEmpty: boolean, ...ValidatorOptions })
Applicable to schemas: STRINGS
Validates that the value is a valid e-mail address
- ast
- functional
#
minmin(value: number | Ref, options = { inclusive: boolean, ...ValidatorOptions})
Applicable to schemas: DATE, STRING, NUMBER, ARRAY
Validates a date, string, number, or array is no less than the given number or ref.
inclusive
is true by default, if passed as false, then the value must be more than min
- ast
- functional
#
maxmax(value: number | Ref, options = { inclusive: boolean = true, ...ValidatorOptions})
Applicable to schemas: DATE, STRING, NUMBER, ARRAY
Validates a date, string, number, or array is no more than the given number or ref.
inclusive
is true by default, if passed as false, then the value must be less than max.
- ast
- functional
#
includesincludes(value: any | Ref, options: ValidatorOptions)
Applicable to schemas: STRING, ARRAY
Validates a string or array value includes the value (or ref):
- ast
- functional
#
oneOfTypeoneOfType(schemas: Schema[], options: ValidatorOptions)
Applicable to schemas: MIXED
This is a special validator (similar to joi's alternatives) that validates a value to be one of a schema type.
- ast
- functional
#
CombinationThere are certain utility validators that can be used to combine/alter validators in certain ways.
#
negateInverts the logic for any validator. This validator is used internally for validator pairs like same/different, is/not and oneOf/notOneOf.
- ast
- functional
#
combineCombines multiple validators into a new validator. Used internally to create the between validator.
- ast
- functional
#
serialEssentially a "real" abortEarly:true
for async validators.
- ast
- functional