aboutsummaryrefslogtreecommitdiffstats
path: root/src/validators.js
diff options
context:
space:
mode:
authorBolek Szewczyk2010-09-23 13:48:17 +0200
committerMisko Hevery2010-09-23 13:50:10 +0200
commit0d5407bc1e976f1f9908d01cfdf848b6c212d135 (patch)
tree2ca0a21c22b42a1720808aaf854dbdd833e3a7ef /src/validators.js
parentdb42221828994a6b3056a96924f4a302e72409d4 (diff)
downloadangular.js-0d5407bc1e976f1f9908d01cfdf848b6c212d135.tar.bz2
make date validator use the Date object
Diffstat (limited to 'src/validators.js')
-rw-r--r--src/validators.js13
1 files changed, 8 insertions, 5 deletions
diff --git a/src/validators.js b/src/validators.js
index b99c8aa9..3eb11f78 100644
--- a/src/validators.js
+++ b/src/validators.js
@@ -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) {