# validate-methods

> 常用验证函数

Latest version **1.1.0** (published 2019-12-20) · MIT license · 0 weekly downloads

## Install

```sh
npm install validate-methods
pnpm add validate-methods
yarn add validate-methods
bun add validate-methods
```

## Health

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

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.0 |
| Published | 2019-12-20 |
| First published | 2019-03-12 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 86.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Author | XueYou |
| Maintainers | xueyou2000 |
| Keywords | validate |

## Links

- npm: https://www.npmjs.com/package/validate-methods
- Repository: https://github.com/xueyou2000/validate-methods
- Homepage: https://github.com/xueyou2000/validate-methods#readme
- Issues: https://github.com/xueyou2000/validate-methods/issues
- npm.io page: https://npm.io/package/validate-methods

## Alternatives

- [@sindresorhus/slugify](https://npm.io/package/@sindresorhus/slugify.md) — 3.7M weekly downloads
- [solid-js](https://npm.io/package/solid-js.md) — 2.7M weekly downloads
- [expo-glass-effect](https://npm.io/package/expo-glass-effect.md) — 2.5M weekly downloads
- [nanoassert](https://npm.io/package/nanoassert.md) — 780.8K weekly downloads
- [@ffmpeg/ffmpeg](https://npm.io/package/@ffmpeg/ffmpeg.md) — 529.5K weekly downloads

## Recent versions

- 1.1.0 (latest) — 2019-12-20
- 1.0.54 — 2019-09-05
- 1.0.53 — 2019-03-19
- 1.0.52 — 2019-03-19
- 1.0.51 — 2019-03-12

## README

# validate-methods

> 这是一个常用的验证函数库, 收集了日期, 邮件, 网址, 银行卡, 身份证等验证函数...

## Install And Usega

Using Browser:

```html
<script src="./dist/index.lib.js"></script>
<script>
    console.log(ValidateMethods.IsEmail("xx@gmail.com") === true);
</script>
```

Or Using npm:

```sh
npm install --save validate-methods
```

```js
import { IsEmail } from "validate-methods";
console.log(IsEmail("xx@gmail.com") === true);
```

## Methods

### 通用验证

-   `Required(value: any)` 验证值是否必填
-   `MinLength(str: string, min: number, equal: boolean = true)` 验证字符串长度是否小于 min
-   `MaxLength(str: string, max: number, equal: boolean = true)` 验证字符串长度是否大于 max
-   `RangeLength(str: string, min: number, max: number, equal: boolean = true)` 验证字符串长度在范围内
-   `EqualLength(str: string, length: number)` 验证字符串长度是否等于 length
-   `Min(val: number | string, min: number, equal: boolean = true)` 验证数值是否小于 min
-   `Max(val: number | string, max: number, equal: boolean = true)` 验证数值是否大于 min
-   `Range(val: number | string, min: number, max: number, equal: boolean = true)` 验证数值是否在某个范围内
-   `Pattern(val: string, regexp: string | RegExp)` 验证字符串是否匹配正则

### 类型验证

-   `IsNumber(number: string | number)` 验证数值类型
-   `IsFunction(func: Function)` 验证函数类型
-   `IsArray(array: any[])` 验证数组类型

### 格式验证

-   `IsEmail(email: string)` 验证邮箱格式
-   `IsUrl(url: string)` 验证网址格式
-   `AcceptSuffix(val: string, suffixs: string[])` 验证合法后缀
-   `ZipCode(val: string)` 验证邮政编码格式
-   `PhoneNo(val: string)` 验证手机号格式
-   `Tel(val: string)` 验证座机号码格式
-   `Chinese(val: string)` 验证是否中文字符
-   `NotChinese(val: string)` 验证是否不包含中文字符
-   `BankCard(card: string)` 验证银行卡号格式
-   `IdCardNo(cardNo: string)` 验证身份证格式

### 日期验证

-   `IsTime(time: string)` 验证时间字符串格式, 如: 10:32:33
-   `IsDateFormat(date: string)` 验证日期字符串格式, 如: 2018-03-26
-   `IsDateISO(date: string)` 验证日期字符串格式, 如: 2018-03-26 10:32:33

### 数值验证

-   `IsDigits(number: number | string)` 验证整数格式
-   `IsStep(val: number | string, step: number)` 验证数值是否为指定倍数
-   `Amount(amount: string | number, canBeZero: boolean = false, bits: number = 6)` 验证金额格式

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