> For the complete documentation index, see [llms.txt](https://racoon-js.gitbook.io/zh/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://racoon-js.gitbook.io/zh/other-common-api/validate.md).

# validate

## 作用

校验被检测值是否符合格式要求。

要数据格式符合要求，则校验通过，返回原始数据，或者返回经过处理后的数据（***`default`***, ***`format`*** 方法可修改返回值）。

否则，校验不通过，会抛出校验错误`ValidateError`, 错误信息`meesage`字段指明了不通过的原因。可通过`error`方法自定义错误文案。

## 参数

* `[value]` ***(\*)***  - 被检测值，可不传，默认为`undefined`.

## 示例

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


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://racoon-js.gitbook.io/zh/other-common-api/validate.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
