File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11.idea /
2- . node_modules /
2+ node_modules /
33.DS_Store
Original file line number Diff line number Diff line change @@ -16,7 +16,7 @@ module.exports = {
1616 * @returns {boolean }
1717 */
1818 isEmail : function ( str ) {
19- return / ^ [ a - z 0 - 9 ! # $ % & ' * + \ /= ? ^ _ ` { | } ~ . - ] + @ [ a - z 0 - 9 - ] + ( \. [ a - z 0 - 9 - ] + ) * $ / i . test ( str ) ;
19+ return / ^ [ a - z A - Z 0 - 9 . ! # $ % & ' * + / = ? ^ _ ` { | } ~ - ] + @ [ a - z A - Z 0 - 9 ] (?: [ a - z A - Z 0 - 9 - ] { 0 , 61 } [ a - z A - Z 0 - 9 ] ) ? (?: \. [ a - z A - Z 0 - 9 ] (?: [ a - z A - Z 0 - 9 - ] { 0 , 61 } [ a - z A - Z 0 - 9 ] ) ? ) * $ / . test ( str ) ;
2020 } ,
2121
2222 /**
Original file line number Diff line number Diff line change 2222 "url" : " https://github.com/SFantasy/node-validator/issues"
2323 },
2424 "homepage" : " https://github.com/SFantasy/node-validator" ,
25- "dependencies" : {}
25+ "dependencies" : {},
26+ "devDependencies" : {
27+ "mocha" : " ^1.21.4"
28+ }
2629}
Original file line number Diff line number Diff line change 1+ /**
2+ *
3+ * test
4+ *
5+ * @description
6+ * @author Fantasy <fantasyshao@icloud.com>
7+ * @create 2014-09-10
8+ * @update 2014-09-10
9+ */
10+
11+ var validator = require ( '../index' ) ;
12+ var assert = require ( 'assert' ) ;
13+ var format = require ( 'util' ) . format ;
14+
15+ function test ( options ) {
16+ var args = options . args || [ ] ;
17+ args . unshift ( null ) ;
18+ if ( options . valid ) {
19+ options . valid . forEach ( function ( valid ) {
20+ args [ 0 ] = valid ;
21+ if ( validator [ options . validator ] . apply ( validator , args ) !== true ) {
22+ var warning = format ( 'validator.%s(%s) failed but should have passed' ,
23+ options . validator , args . join ( ', ' ) ) ;
24+ throw new Error ( warning ) ;
25+ }
26+ } ) ;
27+ }
28+ if ( options . invalid ) {
29+ options . invalid . forEach ( function ( invalid ) {
30+ args [ 0 ] = invalid ;
31+ if ( validator [ options . validator ] . apply ( validator , args ) !== false ) {
32+ var warning = format ( 'validator.%s(%s) passed but should have failed' ,
33+ options . validator , args . join ( ', ' ) ) ;
34+ throw new Error ( warning ) ;
35+ }
36+ } ) ;
37+ }
38+ }
39+
40+ describe ( 'Validate' , function ( ) {
41+
42+ describe ( '#isEmail' , function ( ) {
43+ it ( 'should validate email address' , function ( done ) {
44+ test ( {
45+ validator : 'isEmail' ,
46+ valid : [
47+ 'abc@test.com' ,
48+ 'a0gg@gmail.com' ,
49+ 'test123@abc.com.cn' ,
50+ 'test.123@gmail.com'
51+ ] ,
52+ invalid : [
53+ 'abcd@' ,
54+ '@test.com'
55+ ]
56+ } ) ;
57+
58+ done ( ) ;
59+ } ) ;
60+ } ) ;
61+
62+ } ) ;
You can’t perform that action at this time.
0 commit comments