mirror of
https://github.com/Hopiu/angular.js.git
synced 2026-05-09 23:34:42 +00:00
make date validator use the Date object
This commit is contained in:
parent
db42221828
commit
0d5407bc1e
2 changed files with 21 additions and 7 deletions
|
|
@ -34,11 +34,14 @@ foreach({
|
||||||
return _null;
|
return _null;
|
||||||
},
|
},
|
||||||
|
|
||||||
'date': function(value, min, max) {
|
'date': function(value) {
|
||||||
if (value.match(/^\d\d?\/\d\d?\/\d\d\d\d$/)) {
|
var fields = /^(\d\d?)\/(\d\d?)\/(\d\d\d\d)$/.exec(value);
|
||||||
return _null;
|
var date = fields ? new Date(fields[3], fields[1]-1, fields[2]) : 0;
|
||||||
}
|
return (date &&
|
||||||
return "Value is not a date. (Expecting format: 12/31/2009).";
|
date.getFullYear() == fields[3] &&
|
||||||
|
date.getMonth() == fields[1]-1 &&
|
||||||
|
date.getDate() == fields[2]) ?
|
||||||
|
_null : "Value is not a date. (Expecting format: 12/31/2009).";
|
||||||
},
|
},
|
||||||
|
|
||||||
'ssn': function(value) {
|
'ssn': function(value) {
|
||||||
|
|
|
||||||
|
|
@ -46,8 +46,19 @@ ValidatorTest.prototype.testInteger = function() {
|
||||||
|
|
||||||
ValidatorTest.prototype.testDate = function() {
|
ValidatorTest.prototype.testDate = function() {
|
||||||
var error = "Value is not a date. (Expecting format: 12/31/2009).";
|
var error = "Value is not a date. (Expecting format: 12/31/2009).";
|
||||||
assertEquals(angular.validator.date("ab"), error);
|
expect(angular.validator.date("ab")).toEqual(error);
|
||||||
assertEquals(angular.validator.date("12/31/2009"), null);
|
expect(angular.validator.date("12/31/2009")).toEqual(null);
|
||||||
|
expect(angular.validator.date("1/1/1000")).toEqual(null);
|
||||||
|
expect(angular.validator.date("12/31/9999")).toEqual(null);
|
||||||
|
expect(angular.validator.date("2/29/2004")).toEqual(null);
|
||||||
|
expect(angular.validator.date("2/29/2000")).toEqual(null);
|
||||||
|
expect(angular.validator.date("2/29/2100")).toEqual(error);
|
||||||
|
expect(angular.validator.date("2/29/2003")).toEqual(error);
|
||||||
|
expect(angular.validator.date("41/1/2009")).toEqual(error);
|
||||||
|
expect(angular.validator.date("13/1/2009")).toEqual(error);
|
||||||
|
expect(angular.validator.date("1/1/209")).toEqual(error);
|
||||||
|
expect(angular.validator.date("1/32/2010")).toEqual(error);
|
||||||
|
expect(angular.validator.date("001/031/2009")).toEqual(error);
|
||||||
};
|
};
|
||||||
|
|
||||||
ValidatorTest.prototype.testPhone = function() {
|
ValidatorTest.prototype.testPhone = function() {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue