# wt-form-check

> Extensible form validator for rules

Latest version **1.0.6** (published 2021-04-08) · ISC license · 0 weekly downloads

## Install

```sh
npm install wt-form-check
pnpm add wt-form-check
yarn add wt-form-check
bun add wt-form-check
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.6 |
| Published | 2021-04-08 |
| First published | 2020-04-20 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 17.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | wt |
| Maintainers | wtsml |
| Keywords | formcheck |

## Links

- npm: https://www.npmjs.com/package/wt-form-check
- npm.io page: https://npm.io/package/wt-form-check

## Dependencies (1)

- [@babel/plugin-transform-runtime](https://npm.io/package/@babel/plugin-transform-runtime.md) ^7.13.10

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 1.0.6 (latest) — 2021-04-08
- 1.0.4 — 2020-04-20
- 1.0.3 — 2020-04-20
- 1.0.0 — 2020-04-20

## README

### 安装

```javascript
npm i wt-form-check -S
```
### 基本使用

1.在您的表单 dom 上，添加合适的id
```html
<input type="text" class="form-control" id="name" placeholder="姓名">
```
2.导入 check 方法, (如果需要扩展请往下看),此方法按照下方例子接收一个二维数组，需依次放入`验证规则集`，`表单数据`，`选择器id`，然后方法返回一个 `boolean` 值

```javascript
import { default as check } from 'wt-form-check'

submit() {
    if (!check([
        [['required', 'minlength(1)', 'maxlength(6)'],form.name, 'name'],
        [['required', 'minlength(1)', 'maxlength(18)'],form.password, 'password'],
        [['required', 'mobile'],form.mobile, 'mobile'],
        [['required', 'min(1)', 'max(200)', 'int'],form.age, 'age'],
        [['required', 'minlength(1)', 'maxlength(20)'],form.city, 'city'],
        [['required', 'url'],form.url, 'url'],
    ])) {
        return false
    }
    window.alert('表单验证通过')
}

```

### 扩展规则

1.导入 `extend` 方法，并且传入一个对象或者数组来扩展规则，方法返回一个扩展后的 `check` 方法

```javascript
import { extend } from 'wt-form-check'

let check = extend([
     { reg: /iswt/, method: (rule, data) => parseInt(data) !== 100 ? { pass: false, msg: '数据必须是100' } : { pass: true } }
])

submit() {
    if (!check([
        [['required', 'iswt'],form.name, 'name'],
        [['required', 'minlength(1)', 'maxlength(18)'],form.password, 'password'],
        [['required', 'mobile'],form.mobile, 'mobile'],
        [['required', 'min(1)', 'max(200)', 'int'],form.age, 'age'],
        [['required', 'minlength(1)', 'maxlength(20)'],form.city, 'city'],
        [['required', 'url'],form.url, 'url'],
    ])) {
        return false
    }
    window.alert('表单验证通过')
}
```

---
_Source: https://npm.io/package/wt-form-check · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
