/ Published in: JavaScript
Taken from http://stackoverflow.com/questions/1353684/detecting-an-invalid-date-date-instance-in-javascript
Expand |
Embed | Plain Text
/** check date validation @param: dateStr: string (format: dd/mm/yyyy) **/ function isDate(dateStr) { var s = dateStr.split('/'); //format 21/12/2012 var d = new Date(+s[2], s[1]-1, +s[0]); if (Object.prototype.toString.call(d) === "[object Date]") { if (!isNaN(d.getTime()) && d.getDate() == s[0] && d.getMonth() == (s[1] - 1)) { return true; } } return false; }
You need to login to post a comment.
