Skip to content

Commit 3e9932d

Browse files
committed
v0.0.2
1. Add several validator methods 2. Add example
1 parent 1a06fc8 commit 3e9932d

4 files changed

Lines changed: 50 additions & 3 deletions

File tree

example/example.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/**
2+
*
3+
* example
4+
*
5+
* @description
6+
* @author Fantasy <fantasyshao@icloud.com>
7+
* @create 2014-09-08
8+
* @update 2014-09-08
9+
*/
10+
11+
var validator = require('../lib');
12+
13+
// isEmail
14+
console.log(validator.isEmail('test@gmail.com'));
15+
16+
// isAllChinese
17+
console.log(validator.isAllChinese('测试'));
18+
19+
// isAllEnglish
20+
console.log(validator.isAllEnglish('test'));
21+
22+
// isAllDigit
23+
console.log(validator.isAllDigit('12345'));

index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
*
33
* index
44
*
5-
* @description
5+
* @description entrance
66
* @author Fantasy <fantasyshao@icloud.com>
77
* @create 2014-09-08
88
* @update 2014-09-08

lib/index.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,26 @@
88
* @update 2014-09-08
99
*/
1010

11+
module.exports = {
12+
13+
isEmail: function (str) {
14+
return /^[a-z0-9!#$%&'*+\/=?^_`{|}~.-]+@[a-z0-9-]+(\.[a-z0-9-]+)*$/i.test(str);
15+
},
16+
17+
isAllChinese: function (str) {
18+
return !/[^\u4e00-\u9fa5]/.test(str);
19+
},
20+
21+
isAllEnglish: function (str) {
22+
return /^[a-zA-Z]+$/.test(str);
23+
},
24+
25+
isAllDigit: function (str) {
26+
return /^[0-9]+$/.test(str);
27+
},
28+
29+
isChineseTel: function (str) {
30+
return /^1[34578]\d{9}$/.test(str);
31+
}
32+
33+
};

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "is-valid",
3-
"version": "0.0.1",
3+
"version": "0.0.2",
44
"description": "String validator for more",
55
"main": "index.js",
66
"scripts": {
@@ -21,5 +21,6 @@
2121
"bugs": {
2222
"url": "https://github.com/SFantasy/node-validator/issues"
2323
},
24-
"homepage": "https://github.com/SFantasy/node-validator"
24+
"homepage": "https://github.com/SFantasy/node-validator",
25+
"dependencies": {}
2526
}

0 commit comments

Comments
 (0)