Skip to content

Commit 26a85da

Browse files
committed
update doc and update version1.0
1 parent a8b1568 commit 26a85da

File tree

4 files changed

+31
-85
lines changed

4 files changed

+31
-85
lines changed

README.md

Lines changed: 13 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,18 @@
1-
## based on validate before form submit
1+
## 基于表单提交前验证的库
22

3+
灵感来自于mongoose.Schema 实现一个配置型的表单验证库
34
####
4-
<b>Inspired</b> by mongoose.Schema, achieve an <b>config type</b> form validation library
5-
####
6-
[中文说明](https://github.com/pagewang0/form-validation/blob/master/README_CN.md)
5+
[English](https://github.com/pagewang0/form-validation/blob/master/README_EN.md)
76

8-
###
97
Feature:
10-
* single input item validate (synchronous and asynchronous)
11-
* based on validate before form submit
12-
* provide field.get method get field value
13-
* DIY validation method
14-
15-
```javascript
16-
var validator = new Validator({
17-
username: {required: true, length: {max: 11, min: 6}},
18-
password: {required: true, length: {max: 11, min: 6}},
19-
confirm: {equal: 'password'},
20-
email: {required: true, type: 'email'},
21-
sex: {required: true, enum: ['', '', '保密']},
22-
phone: {required: true, type: Number, length: 11},
23-
})
24-
25-
var messages = validator.messages({
26-
username: {required: '用户名是必须的', length: {max: '用户名长度超过最大值', min: '用户名长度小于最小值'}},
27-
password: {required: '密码是必须的', length: {max: '密码长度超过最大值', min: '密码长度小于最小值'}},
28-
confirm: {equal: '确认密码必须和密码保持一致'},
29-
email: {required: 'email是必须的', type: 'email格式不正确'},
30-
sex: {required: '性别是必须的', enum: '性别输入值不在限定范围之内'},
31-
phone: {required: '手机号码是必须的', type: '手机号码值类型错误', length: '手机号码长度必须为11'}
32-
})
33-
34-
validator.path('username').validate(function(field, username, done) {
35-
request('/username')
36-
.query({username: username})
37-
.end((err, res) => {
38-
if (err) {
39-
done(err, field)
40-
return
41-
};
42-
done()
43-
})
44-
}, '用户名已存在')
45-
```
8+
* 提供基本验证功能
9+
* 提供可扩展的验证方法来支持同步/异步验证
10+
* 错误信息/样式的set/reset
11+
* 通用/指定的获取字段值方法
12+
* 支持单个字段的同步/异步验证
13+
* 提供submit callback方法
14+
* 提供获取error信息对象集合
4615

47-
ps: I am english is poor, please forgive...
16+
基本用法见example, 提供了
17+
[base](https://github.com/pagewang0/form-validation/tree/master/examples/base), [angularjs](https://github.com/pagewang0/form-validation/tree/master/examples/angularjs), [react](https://github.com/pagewang0/form-validation/tree/master/examples/react)
18+
三种用法

README_CN.md

Lines changed: 0 additions & 42 deletions
This file was deleted.

README_EN.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
## based on validate before form submit
2+
3+
####
4+
Inspired by mongoose.Schema, achieve an config type form validation library
5+
6+
###
7+
Feature:
8+
* provide base validation
9+
* provide can be extend validate method support async/sync validate
10+
* error message/ style of set/reset
11+
* general/one field get value method
12+
* support one field async/sync validate
13+
* provide submit callback method
14+
* provide get errors messages method
15+
16+
basic usage see example:
17+
[base](https://github.com/pagewang0/form-validation/tree/master/examples/base), [angularjs](https://github.com/pagewang0/form-validation/tree/master/examples/angularjs), [react](https://github.com/pagewang0/form-validation/tree/master/examples/react)

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "form-validation",
3-
"version": "0.0.1",
3+
"version": "1.0.0",
44
"description": "form validation",
55
"main": "index.js",
66
"directories": {

0 commit comments

Comments
 (0)