We Recommend

Pro JavaScript Techniques Pro JavaScript Techniques
Pro JavaScript Techniques is the ultimate JavaScript book for the modern web developer. It provides everything you need to know about modern JavaScript, and shows what JavaScript can do for your web sites. This book doesn't waste any time looking at things you already know, like basic syntax and structures.


Posted By

Leech on 07/21/06


Tagged

date validation


Versions (?)


Who likes this?

5 people have marked this snippet as a favorite

mate
meth
jkochis
funtom
vali29


Valid Date v1.0


Published in: JavaScript 


URL: http://jsfromhell.com/geral/is-date

Date validation. Created: 2006.04.25

  1. /**************************************
  2. * Jonas Raoni Soares Silva
  3. * http://www.joninhas.ath.cx
  4. **************************************/
  5.  
  6. isDate = function(y, m, d){ //v1.0
  7. if(typeof y == "string" && m instanceof RegExp && d){
  8. if(!m.test(y)) return 1;
  9. y = RegExp["$" + d.y], m = RegExp["$" + d.m], d = RegExp["$" + d.d];
  10. }
  11. d = Math.abs(d) || 0, m = Math.abs(m) || 0, y = Math.abs(y) || 0;
  12. return arguments.length != 3 ? 1 : d < 1 || d > 31 ? 2 : m < 1 || m > 12 ? 3 : /4|6|9|11/.test(m) && d == 31 ? 4
  13. : m == 2 && (d > ((y = !(y % 4) && (y % 1e2) || !(y % 4e2)) ? 29 : 28)) ? 5 + !!y : 0;
  14. };

Report this snippet 

You need to login to post a comment.