> 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/jie-kou-shuo-ming/array/custom.md).

# custom

## 作用

通过函数`callback`声明自定义限制器。

## 参数

* `callback` ***(function)*** - 用于自定义限制器的函数。*`callback`有一个参数：被检测值***。**&#x5982;果检测不通过，则需要抛出错误，否则，表示检测通过。
* `ctx` ***(\*)*** *callback* 执行的上下文`this`.

> 说明
>
> 从1.3.0版本开始，若检测不通过，`callback`也可以返回非空字符串，字符串你内容代表不通过原因。否则，返回其它值将表示检测通过。

## 示例

```javascript
const schema = racoon.object().custom((val) => {
  if (val.includes(1)) {
    return true;
  }
  throw new Error('被检测数组必须包含数字1');
});
schema.validate([1, 2]); // pass
schema.validate([2, 3]); // fail
```
