mirror of
https://github.com/Hopiu/angular.js.git
synced 2026-03-17 07:40:22 +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;
|
||||
},
|
||||
|
||||
'date': function(value, min, max) {
|
||||
if (value.match(/^\d\d?\/\d\d?\/\d\d\d\d$/)) {
|
||||
return _null;
|
||||
}
|
||||
return "Value is not a date. (Expecting format: 12/31/2009).";
|
||||
'date': function(value) {
|
||||
var fields = /^(\d\d?)\/(\d\d?)\/(\d\d\d\d)$/.exec(value);
|
||||
var date = fields ? new Date(fields[3], fields[1]-1, fields[2]) : 0;
|
||||
return (date &&
|
||||
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) {
|
||||
|
|
|
|||
|
|
@ -46,8 +46,19 @@ ValidatorTest.prototype.testInteger = function() {
|
|||
|
||||
ValidatorTest.prototype.testDate = function() {
|
||||
var error = "Value is not a date. (Expecting format: 12/31/2009).";
|
||||
assertEquals(angular.validator.date("ab"), error);
|
||||
assertEquals(angular.validator.date("12/31/2009"), null);
|
||||
expect(angular.validator.date("ab")).toEqual(error);
|
||||
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() {
|
||||
|
|
|
|||
Loading…
Reference in a new issue