validate

validate([value])

Effect

Validate the detected value is legal or not.

If validate passed, return the original value or the value after processing. (Because default and format can modify the final return value.)

Otherwise, if validate failed, it will throw a ValidateError. The message prop of ValdiateError points to the failure reason. You can set some custom error messages by calling error.

Arguments

  • [value] (*) - The value to detect, default is undefined.

Returns

The original value or the value after processing.

Example

const schema = racoon.number().min(0);
try {
  schema.validate(2);
  // pass
} catch (error) {
  // fail
}

Last updated