Answer by user1296274 for Detecting an "invalid date" Date instance in...
This just worked for me new Date('foo') == 'Invalid Date'; //is true However this didn't work new Date('foo') === 'Invalid Date'; //is false
View ArticleAnswer by Mina Gabriel for Detecting an "invalid date" Date instance in...
you can convert your date and time to milliseconds getTime() this getTime() Method return Not a Number NaN when not valid if(!isNaN(new Date("2012/25/255").getTime())) return 'valid date time'; return...
View ArticleAnswer by Denis Ryzhkov for Detecting an "invalid date" Date instance in...
For int 1-based components of a date: var is_valid_date = function(year, month, day) { var d = new Date(year, month - 1, day); return d.getFullYear() === year && (d.getMonth() + 1) === month...
View ArticleAnswer by Yves M. for Detecting an "invalid date" Date instance in JavaScript
You can simply use moment.js Here is an example: var m = moment('2015-11-32', 'YYYY-MM-DD'); m.isValid(); // false The validation section in the documentation is quite clear. And also, the following...
View ArticleAnswer by kam for Detecting an "invalid date" Date instance in JavaScript
Date object to string is more simple and reliable way to detect if both fields are valid date. e.g. If you enter this "-------" to the date input field. Some of the above answers won't work....
View ArticleAnswer by Matt Campbell for Detecting an "invalid date" Date instance in...
Would like to mention that the jQuery UI DatePicker widget has a very good date validator utility method that checks for format and validity (e.g., no 01/33/2013 dates allowed). Even if you don't want...
View ArticleAnswer by Michael Goldshmidt for Detecting an "invalid date" Date instance in...
IsValidDate: function(date) { var regex = /\d{1,2}\/\d{1,2}\/\d{4}/; if (!regex.test(date)) return false; var day = Number(date.split("/")[1]); date = new Date(date); if (date && date.getDate()...
View ArticleAnswer by Ash Clarke for Detecting an "invalid date" Date instance in JavaScript
My solution is for simply checking whether you get a valid date object: Implementation Date.prototype.isValid = function () { // An invalid date object returns NaN for getTime() and NaN is the only //...
View ArticleAnswer by Dex for Detecting an "invalid date" Date instance in JavaScript
None of these answers worked for me (tested in Safari 6.0) when trying to validate a date such as 2/31/2012, however, they work fine when trying any date greater than 31. So I had to brute force a...
View ArticleAnswer by John for Detecting an "invalid date" Date instance in JavaScript
None of the above solutions worked for me what did work however is function validDate (d) { var date = new Date(d); var day = ""+date.getDate(); if( day.length == 1)day = "0"+day; var month = "" +(...
View ArticleAnswer by Yusef Mohamadi for Detecting an "invalid date" Date instance in...
you can check the valid format of txDate.value with this scirpt. if it was in incorrect format the Date obejct not instanced and return null to dt . var dt = new Date(txtDate.value) if (isNaN(dt)) And...
View ArticleAnswer by Jingguo Yao for Detecting an "invalid date" Date instance in...
I use the following code to validate values for year, month and date. function createDate(year, month, _date) { var d = new Date(year, month, _date); if (d.getFullYear() != year || d.getMonth() !=...
View ArticleAnswer by Raz for Detecting an "invalid date" Date instance in JavaScript
Inspired by Borgar's approach I have made sure that the code not only validates the date, but actually makes sure the date is a real date, meaning that dates like 31/09/2011 and 29/02/2011 are not...
View ArticleAnswer by user889209 for Detecting an "invalid date" Date instance in JavaScript
I think some of this is a long process. We can cut it short as shown below: function isValidDate(dateString) { debugger; var dateStringSplit; var formatDate; if (dateString.length >= 8 &&...
View ArticleAnswer by faridz for Detecting an "invalid date" Date instance in JavaScript
// check whether date is valid var t = new Date('2011-07-07T11:20:00.000+00:00x'); valid = !isNaN(t.valueOf());
View ArticleAnswer by Dmytro Shevchenko for Detecting an "invalid date" Date instance in...
Nice solution! Included in my library of auxiliary functions, now it looks like this: Object.isDate = function(obj) { /// <summary> /// Determines if the passed object is an instance of Date. ///...
View ArticleAnswer by broox for Detecting an "invalid date" Date instance in JavaScript
I really liked Christoph's approach (but didn't have enough of a reputation to vote it up). For my use, I know I will always have a Date object so I just extended date with a valid() method....
View ArticleAnswer by Christoph for Detecting an "invalid date" Date instance in JavaScript
You can check the validity of a Date object d via d instanceof Date && isFinite(d) To avoid cross-frame issues, one could replace the instanceof check with Object.prototype.toString.call(d) ===...
View ArticleAnswer by Borgar for Detecting an "invalid date" Date instance in JavaScript
Here's how I would do it: if (Object.prototype.toString.call(d) === "[object Date]") { // it is a date if (isNaN(d.getTime())) { // d.valueOf() could also work // date is not valid } else { // date is...
View ArticleAnswer by Ash for Detecting an "invalid date" Date instance in JavaScript
Instead of using new Date() you should use: var timestamp = Date.parse('foo'); if (isNaN(timestamp) == false) { var d = new Date(timestamp); } Date.parse() returns a timestamp, an integer representing...
View Article