This repository was archived by the owner on Apr 12, 2024. It is now read-only.
File tree 2 files changed +21
-7
lines changed
2 files changed +21
-7
lines changed Original file line number Diff line number Diff line change @@ -34,11 +34,14 @@ foreach({
34
34
return _null ;
35
35
} ,
36
36
37
- 'date' : function ( value , min , max ) {
38
- if ( value . match ( / ^ \d \d ? \/ \d \d ? \/ \d \d \d \d $ / ) ) {
39
- return _null ;
40
- }
41
- return "Value is not a date. (Expecting format: 12/31/2009)." ;
37
+ 'date' : function ( value ) {
38
+ var fields = / ^ ( \d \d ? ) \/ ( \d \d ? ) \/ ( \d \d \d \d ) $ / . exec ( value ) ;
39
+ var date = fields ? new Date ( fields [ 3 ] , fields [ 1 ] - 1 , fields [ 2 ] ) : 0 ;
40
+ return ( date &&
41
+ date . getFullYear ( ) == fields [ 3 ] &&
42
+ date . getMonth ( ) == fields [ 1 ] - 1 &&
43
+ date . getDate ( ) == fields [ 2 ] ) ?
44
+ _null : "Value is not a date. (Expecting format: 12/31/2009)." ;
42
45
} ,
43
46
44
47
'ssn' : function ( value ) {
Original file line number Diff line number Diff line change @@ -46,8 +46,19 @@ ValidatorTest.prototype.testInteger = function() {
46
46
47
47
ValidatorTest . prototype . testDate = function ( ) {
48
48
var error = "Value is not a date. (Expecting format: 12/31/2009)." ;
49
- assertEquals ( angular . validator . date ( "ab" ) , error ) ;
50
- assertEquals ( angular . validator . date ( "12/31/2009" ) , null ) ;
49
+ expect ( angular . validator . date ( "ab" ) ) . toEqual ( error ) ;
50
+ expect ( angular . validator . date ( "12/31/2009" ) ) . toEqual ( null ) ;
51
+ expect ( angular . validator . date ( "1/1/1000" ) ) . toEqual ( null ) ;
52
+ expect ( angular . validator . date ( "12/31/9999" ) ) . toEqual ( null ) ;
53
+ expect ( angular . validator . date ( "2/29/2004" ) ) . toEqual ( null ) ;
54
+ expect ( angular . validator . date ( "2/29/2000" ) ) . toEqual ( null ) ;
55
+ expect ( angular . validator . date ( "2/29/2100" ) ) . toEqual ( error ) ;
56
+ expect ( angular . validator . date ( "2/29/2003" ) ) . toEqual ( error ) ;
57
+ expect ( angular . validator . date ( "41/1/2009" ) ) . toEqual ( error ) ;
58
+ expect ( angular . validator . date ( "13/1/2009" ) ) . toEqual ( error ) ;
59
+ expect ( angular . validator . date ( "1/1/209" ) ) . toEqual ( error ) ;
60
+ expect ( angular . validator . date ( "1/32/2010" ) ) . toEqual ( error ) ;
61
+ expect ( angular . validator . date ( "001/031/2009" ) ) . toEqual ( error ) ;
51
62
} ;
52
63
53
64
ValidatorTest . prototype . testPhone = function ( ) {
You can’t perform that action at this time.
0 commit comments