When I want to check that a string is a date in Javascript, I usually do something like:
!isNaN(Date.parse(myString));
But I just discovered that
isNaN(Date.parse("smth")) === true
isNaN(Date.parse("smth_1")) === true
isNaN(Date.parse("1 smth")) === true
isNaN(Date.parse("smth 1")) === false // !!
See this fiddle.
So my question is: why does any string ending with a number (with a space before) parse as a valid date (which it is obviously not), and how to reliably check that it's not ?