# validator.js
[![NPM version][npm-image]][npm-url]
[![CI][ci-image]][ci-url]
[![Coverage][codecov-image]][codecov-url]
[![Downloads][downloads-image]][npm-url]
[![Backers on Open Collective](https://opencollective.com/validatorjs/backers/badge.svg)](#backers)
[![Sponsors on Open Collective](https://opencollective.com/validatorjs/sponsors/badge.svg)](#sponsors)
[![Gitter][gitter-image]][gitter-url]
[![Disclose a vulnerability][huntr-image]][huntr-url]
A library of string validators and sanitizers.
## Strings only
**This library validates and sanitizes strings only.**
If you're not sure if your input is a string, coerce it using `input + ''`.
Passing anything other than a string will result in an error.
## Installation and Usage
### Server-side usage
Install the library with `npm install validator`
#### No ES6
```javascript
var validator = require('validator');
validator.isEmail('foo@bar.com'); //=> true
```
#### ES6
```javascript
import validator from 'validator';
```
Or, import only a subset of the library:
```javascript
import isEmail from 'validator/lib/isEmail';
```
#### Tree-shakeable ES imports
```javascript
import isEmail from 'validator/es/lib/isEmail';
```
### Client-side usage
The library can be loaded either as a standalone script, or through an [AMD][amd]-compatible loader
```html
<script type="text/javascript" src="validator.min.js"></script>
<script type="text/javascript">
validator.isEmail('foo@bar.com'); //=> true
</script>
```
The library can also be installed through [bower][bower]
```bash
$ bower install validator-js
```
CDN
```html
<script src="https://unpkg.com/validator@latest/validator.min.js"></script>
```
## Contributors
[Become a backer](https://opencollective.com/validatorjs#backer)
[Become a sponsor](https://opencollective.com/validatorjs#sponsor)
Thank you to the people who have already contributed:
<a href="https://github.com/validatorjs/validator.js/graphs/contributors"><img src="https://opencollective.com/validatorjs/contributors.svg?width=890" /></a>
## Validators
Here is a list of the validators currently available.
Validator | Description
--------------------------------------- | --------------------------------------
**contains(str, seed [, options])** | check if the string contains the seed.<br/><br/>`options` is an object that defaults to `{ ignoreCase: false, minOccurrences: 1 }`.<br />Options: <br/> `ignoreCase`: Ignore case when doing comparison, default false.<br/>`minOccurences`: Minimum number of occurrences for the seed in the string. Defaults to 1.
**equals(str, comparison)** | check if the string matches the comparison.
**isAfter(str [, options])** | check if the string is a date that is after the specified date.<br/><br/>`options` is an object that defaults to `{ comparisonDate: Date().toString() }`.<br/>**Options:**<br/>`comparisonDate`: Date to compare to. Defaults to `Date().toString()` (now).
**isAlpha(str [, locale, options])** | check if the string contains only letters (a-zA-Z).<br/><br/>`locale` is one of `['ar', 'ar-AE', 'ar-BH', 'ar-DZ', 'ar-EG', 'ar-IQ', 'ar-JO', 'ar-KW', 'ar-LB', 'ar-LY', 'ar-MA', 'ar-QA', 'ar-QM', 'ar-SA', 'ar-SD', 'ar-SY', 'ar-TN', 'ar-YE', 'bg-BG', 'bn', 'cs-CZ', 'da-DK', 'de-DE', 'el-GR', 'en-AU', 'en-GB', 'en-HK', 'en-IN', 'en-NZ', 'en-US', 'en-ZA', 'en-ZM', 'es-ES', 'fa-IR', 'fi-FI', 'fr-CA', 'fr-FR', 'he', 'hi-IN', 'hu-HU', 'it-IT', 'kk-KZ', 'ko-KR', 'ja-JP', 'ku-IQ', 'nb-NO', 'nl-NL', 'nn-NO', 'pl-PL', 'pt-BR', 'pt-PT', 'ru-RU', 'si-LK', 'sl-SI', 'sk-SK', 'sr-RS', 'sr-RS@latin', 'sv-SE', 'th-TH', 'tr-TR', 'uk-UA']` and defaults to `en-US`. Locale list is `validator.isAlphaLocales`. `options` is an optional object that can be supplied with the following key(s): `ignore` which can either be a String or RegExp of characters to be ignored e.g. " -" will ignore spaces and -'s.
**isAlphanumeric(str [, locale, options])** | check if the string contains only letters and numbers (a-zA-Z0-9).<br/><br/>`locale` is one of `['ar', 'ar-AE', 'ar-BH', 'ar-DZ', 'ar-EG', 'ar-IQ', 'ar-JO', 'ar-KW', 'ar-LB', 'ar-LY', 'ar-MA', 'ar-QA', 'ar-QM', 'ar-SA', 'ar-SD', 'ar-SY', 'ar-TN', 'ar-YE', 'bn', 'bg-BG', 'cs-CZ', 'da-DK', 'de-DE', 'el-GR', 'en-AU', 'en-GB', 'en-HK', 'en-IN', 'en-NZ', 'en-US', 'en-ZA', 'en-ZM', 'es-ES', 'fa-IR', 'fi-FI', 'fr-CA', 'fr-FR', 'he', 'hi-IN', 'hu-HU', 'it-IT', 'kk-KZ', 'ko-KR', 'ja-JP','ku-IQ', 'nb-NO', 'nl-NL', 'nn-NO', 'pl-PL', 'pt-BR', 'pt-PT', 'ru-RU', 'si-LK', 'sl-SI', 'sk-SK', 'sr-RS', 'sr-RS@latin', 'sv-SE', 'th-TH', 'tr-TR', 'uk-UA']`) and defaults to `en-US`. Locale list is `validator.isAlphanumericLocales`. `options` is an optional object that can be supplied with the following key(s): `ignore` which can either be a String or RegExp of characters to be ignored e.g. " -" will ignore spaces and -'s.
**isAscii(str)** | check if the string contains ASCII chars only.
**isBase32(str [, options])** | check if the string is base32 encoded. `options` is optional and defaults to `{ crockford: false }`.<br/> When `crockford` is true it tests the given base32 encoded string using [Crockford's base32 alternative][Crockford Base32].
**isBase58(str)** | check if the string is base58 encoded.
**isBase64(str [, options])** | check if the string is base64 encoded. `options` is optional and defaults to `{ urlSafe: false }`<br/> when `urlSafe` is true it tests the given base64 encoded string is [url safe][Base64 URL Safe].
**isBefore(str [, date])** | check if the string is a date that is before the specified date.
**isBIC(str)** | check if the string is a BIC (Bank Identification Code) or SWIFT code.
**isBoolean(str [, options])** | check if the string is a boolean.<br/>`options` is an object which defaults to `{ loose: false }`. If `loose` is is set to false, the validator will strictly match ['true', 'false', '0', '1']. If `loose` is set to true, the validator will also match 'yes', 'no', and will match a valid boolean string of any case. (e.g.: ['true', 'True', 'TRUE']).
**isBtcAddress(str)** | check if the string is a valid BTC address.
**isByteLength(str [, options])** | check if the string's length (in UTF-8 bytes) falls in a range.<br/><br/>`options` is an object which defaults to `{ min: 0, max: undefined }`.
**isCreditCard(str [, options])** | check if the string is a credit card number.<br/><br/> `options` is an optional object that can be supplied with the following key(s): `provider` is an optional key whose value should be a string, and defines the company issuing the credit card. Valid values include `['amex', 'dinersclub', 'discover', 'jcb', 'mastercard', 'unionpay', 'visa']` or blank will check for any provider.
**isCurrency(str [, options])** | check if the string is a valid currency amount.<br/><br/>`options` is an object which defaults to `{ symbol: '$', require_symbol: false, allow_space_after_symbol: false, symbol_after_digits: false, allow_negatives: true, parens_for_negatives: false, negative_sign_before_digits: false, negative_sign_after_digits: false, allow_negative_sign_placeholder: false, thousands_separator: ',', decimal_separator: '.', allow_decimal: true, require_decimal: false, digits_after_decimal: [2], allow_space_after_digits: false }`.<br/>**Note:** The array `digits_after_decimal` is filled with the exact number of digits allowed not a range, for example a range 1 to 3 will be given as [1, 2, 3].
**isDataURI(str)** | check if the string is a [data uri format][Data URI Format].
**isDate(str [, options])** | check if the string is a valid date. e.g. [`2002-07-15`, new Date()].<br/><br/> `options` is an object which can contain the keys `format`, `strictMode` and/or `delimiters`.<br/><br/>`format` is a string and defaults to `YYYY/MM/DD`.<br/><br/>`strict
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
【项目资源】: 包含前端、后端、移动开发、操作系统、人工智能、物联网、信息化管理、数据库、硬件开发、大数据、课程资源、音视频、网站开发等各种技术项目的源码。 包括STM32、ESP8266、PHP、QT、Linux、iOS、C++、Java、python、web、C#、EDA、proteus、RTOS等项目的源码。 【项目质量】: 所有源码都经过严格测试,可以直接运行。 功能在确认正常工作后才上传。 【适用人群】: 适用于希望学习不同技术领域的小白或进阶学习者。 可作为毕设项目、课程设计、大作业、工程实训或初期项目立项。 【附加价值】: 项目具有较高的学习借鉴价值,也可直接拿来修改复刻。 对于有一定基础或热衷于研究的人来说,可以在这些基础代码上进行修改和扩展,实现其他功能。 【沟通交流】: 有任何使用上的问题,欢迎随时与博主沟通,博主会及时解答。 鼓励下载和使用,并欢迎大家互相学习,共同进步。
资源推荐
资源详情
资源评论
收起资源包目录
基于node.js+express+sequelize+mysql后端通用模板.zip (2000个子文件)
moment-with-locales.js 607KB
lodash.js 531KB
locales.js 438KB
moment-with-locales.min.js 360KB
locales.min.js 303KB
moment.js 171KB
moment.js 151KB
wkx.js 139KB
model.js 110KB
query-generator.js 89KB
lodash.min.js 71KB
wkx.min.js 64KB
moment.min.js 57KB
index.js 43KB
index.js 40KB
query-generator.js 35KB
index.js 33KB
query-generator.js 32KB
sbcs-data-generated.js 31KB
query-generator.js 31KB
_stream_readable.js 31KB
query-generator.js 28KB
response.js 27KB
query-interface.js 24KB
sequelize.js 23KB
belongs-to-many.js 23KB
dbcs-codec.js 21KB
index.js 21KB
_stream_writable.js 20KB
query-generator.js 20KB
ipaddr.js 19KB
query.js 19KB
index.js 18KB
query.js 18KB
data-types.js 18KB
query-generator.js 17KB
query.js 16KB
_baseConvert.js 16KB
tests.js 15KB
query-generator.js 15KB
index.js 15KB
application.js 14KB
range.js 14KB
utils.js 13KB
query.js 13KB
data-types.js 13KB
day-of-week.js 13KB
query.js 12KB
promise.test.js 12KB
request.js 12KB
index.js 12KB
query.js 12KB
has-many.js 12KB
geometry.js 12KB
toposort.js 11KB
data-types.js 10KB
index.js 10KB
template.js 10KB
month.js 10KB
_mapping.js 10KB
ipaddr.min.js 10KB
connection-manager.js 9KB
ru.js 9KB
query.js 9KB
utf7.js 9KB
query.js 9KB
instance-validator.js 9KB
connection-manager.js 9KB
semver.js 9KB
extend-node.js 8KB
query-interface.js 8KB
data-types.js 8KB
ru.js 8KB
ru.js 8KB
yallist.js 8KB
query.js 8KB
dbcs-data.js 8KB
polygon.js 8KB
seq-queue-test.js 8KB
index.js 8KB
from-string.js 8KB
era.js 8KB
query-interface.js 8KB
cs.js 8KB
_stream_transform.js 8KB
locales.js 8KB
mr.js 8KB
re.js 8KB
has-one.js 7KB
subset.js 7KB
hi.js 7KB
sql.js 7KB
sl.js 7KB
index.js 7KB
offset.js 7KB
values.js 7KB
wrapperLodash.js 7KB
uk.js 7KB
index.js 7KB
cs.js 7KB
共 2000 条
- 1
- 2
- 3
- 4
- 5
- 6
- 20
资源评论
妄北y
- 粉丝: 1w+
- 资源: 1万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功