File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -37,6 +37,22 @@ validator.isEmail('abc@gmail.com'); // => true
3737- isChineseTel(str): check if it is a Chinese cell-phone number
3838- isChineseIdCard(str): check if it is a 18-digit Chinese ID card number
3939
40+ ## Test
41+
42+ ```
43+ git clone git@github.com:SFantasy/node-validator.git && cd node-validator
44+
45+ [sudo] npm install mocha -g
46+
47+ mocha
48+ ```
49+
50+ or
51+
52+ ```
53+ npm test
54+ ```
55+
4056## License
4157
4258The MIT License
Original file line number Diff line number Diff line change 44 "description" : " String validator for more" ,
55 "main" : " index.js" ,
66 "scripts" : {
7- "test" : " echo \" Error: no test specified \" && exit 1 "
7+ "test" : " ./node_modules/.bin/_mocha "
88 },
99 "repository" : {
1010 "type" : " git" ,
Original file line number Diff line number Diff line change @@ -40,7 +40,7 @@ function test(options) {
4040describe ( 'Validate' , function ( ) {
4141
4242 describe ( '#isEmail' , function ( ) {
43- it ( 'should validate email address' , function ( done ) {
43+ it ( 'should validate email address' , function ( ) {
4444 test ( {
4545 validator : 'isEmail' ,
4646 valid : [
@@ -54,8 +54,56 @@ describe('Validate', function () {
5454 '@test.com'
5555 ]
5656 } ) ;
57+ } ) ;
58+ } ) ;
59+
60+ describe ( '#isAllChinese' , function ( ) {
61+ it ( 'should validate all Chinese characters' , function ( ) {
62+ test ( {
63+ validator : 'isAllChinese' ,
64+ valid : [
65+ '你好世界'
66+ ] ,
67+ invalid : [
68+ 'hello world' ,
69+ '你好world' ,
70+ '你好 世界' ,
71+ '你好123world'
72+ ]
73+ } ) ;
74+ } ) ;
75+ } ) ;
76+
77+ describe ( '#isAllEnglish' , function ( ) {
78+ it ( 'should validate all English characters' , function ( ) {
79+ test ( {
80+ validator : 'isAllEnglish' ,
81+ valid : [
82+ 'HelloWorld'
83+ ] ,
84+ invalid : [
85+ 'Hello世界' ,
86+ '你好世界' ,
87+ '你好123world' ,
88+ 'Hello World'
89+ ]
90+ } ) ;
91+ } ) ;
92+ } ) ;
5793
58- done ( ) ;
94+ describe ( '#isAllDigit' , function ( ) {
95+ it ( 'should validate all digits' , function ( ) {
96+ test ( {
97+ validator : 'isAllDigit' ,
98+ valid : [
99+ '12345'
100+ ] ,
101+ invalid : [
102+ '123哈哈' ,
103+ 'HelloWorld33' ,
104+ '你好世界'
105+ ]
106+ } ) ;
59107 } ) ;
60108 } ) ;
61109
You can’t perform that action at this time.
0 commit comments