Validations
A Validation allows you to define a transformation or rejection that will be applied to data before flushing to the database.
Validations are simple function accepting a value in input and returning a new value or throwing an error. Validations can be async by returning a promise.
General validations
required
required
Validation.required(message: String)
Enforce that the field is set, throw an error with message
otherwise.
default
default
Validation.default(value: Mixed)
Defaults the value of the field if non existant. It doesn't reject the valuation, only transform the data set.
String Validations
minLength
minLength
Validation.minLength(min: Number, message: String)
Enforce that the string value is at least min
characters long.
maxLength
maxLength
Validation.maxLength(max: Number, message: String)
Enforce that the string value is less than max
characters long.
regExp
regExp
Validation.regExp(re: RegExp, message: String)
Enforce that the string value match a RegExp (re
).
oneOf
oneOf
Validation.oneOf(constants: Array, message: String)
Enforce that the value is one of the constants.
Iterable Validations
limitAt
limitAt
Validation.limitAt(max: Number)
Enforce that iterable doesn't have more than max
element, it does not throw error, but normalize the value.
Last updated