> 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/any/required.md).

# required

required(\[strict=false])

## 作用

限制被检测值不为`undefined | null | NaN`.

若开启严格模&#x5F0F;***(strict=true)***, 则被检测值不允许为`undefined | null | NaN | '' | {} | []`。

## 参数

* `[strict]` ***(boolean)*** - 是否开启严格模式，可不传，默认为`false`不开启。若明确设置`strict=true`则开启严格模式。

## 示例

```javascript
const schema1 = racoon.any();
schema1.validate(undefined); // pass, 返回值为 undefined
schema1.validate(null); // pass, 返回值为 null
schema1.validate(NaN); // pass, 返回值为 NaN
schema1.validate(''); // pass, 返回值为 空字符串
schema1.validate({}); // pass, 返回值为 {}
schema1.validate([]); // pass, 返回值为 []

const schema2 = racoon.any().required();
schema2.validate(undefined); // fail
schema2.validate(null); // fail
schema2.validate(NaN); // fail
schema1.validate(''); // pass, 返回值为 空字符串
schema1.validate({}); // pass, 返回值为 {}
schema1.validate([]); // pass, 返回值为 []

const schema3 = racoon.any().required(true);
schema2.validate(undefined); // fail
schema2.validate(null); // fail
schema2.validate(NaN); // fail
schema1.validate(''); // fail
schema1.validate({}); // fail
schema1.validate([]); // fail
```
