API Reference
Last updated
Was this helpful?
Last updated
Was this helpful?
validate(value, schema, [rootName])
Validates a value using the given schema.
value
A value to validate.
schema
A schema definition.
rootName
The optional name of the root objected. Used when formatting validation errors.
A validated object.
A ValidationError
is throws if validation failed.
getValidateResult(value, schema, [path])
Validate a value using the given schema, and get result as an object.
value
A value to validate.
schema
A schema definition.
path
The prefix path used for formatting validation errors.
An object with the following props:
value
The new value after validation.
errors
The list of validation errors. If the validation was successful an array will be empty.
Matches any object. By default it's required, and non nullable.
Marks a key as optional. undefined
value is allowed.
Marks a key as required. null
value is allowed.
Matches a string.
Specifies the minimum number of characters.
Specifies the maximum number of characters.
Trims the output value.
Defines a regular expression.
Requires the string value to be a valid email address.
The Following regexp is used /^[a-zA-Z0-9._\-+]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/
Matches an object.
If keys
are not set then any object is allowed.
Defines a schema for each property.
Allows unknown keys.
Matches an array.
Defines the schema of the array element.
Matches predefined list of values. Values are case insensitive.
Defines the required enum value.
Example:
Defines allowed literal values.
Example:
Matches a number. Valid string numbers are casted to a number type.
Requires the number to be an integer (no floating point).
Specifies the minimum allowed number.
Specifies the maximum allowed number.
Matches a boolean. Strings 'true'
and 'false'
are casted to a boolean type.
Matches a date. Valid iso strings e.g. "2018-12-01T14:08:26.061Z"
are converted to a date object. Invalid dates are not allowed e.g. new Date('')
.