var d=new Date("2013-01-25 22:31:55.809231")
alert(d.getDate())
gives NaN in FF and IE and 25 in Chrome... regExing it, as per Ali's suggestion would appear much more sensible
I didn't say to convert it to a date object that way - just that it needs to be converted to a date object in order to confirm that it is an actual date.
Ali's suggestion would not work correctly if the value supplied were "2013-52-76 92:81:85.809231" as it would simply return part of the garbage supplied instead of recognising that it is garbage.
rnd_me has supplied the correct fix for being able to load it into a date object properly.
I think a better question might be: Where did that string come from?
If it came from server-side code, which seems pretty darned likely to me, then why not fix the problem in the server.
Or, if you know it came from reliable server-side code, then even the first answer by LogicAli is sufficient. I doubt seriously that he is worried about some user entering a date time string like that willy-nilly. Why validate it via JS when *almost* surely it comes from some computerized process (likely a DB field?) in the first place.
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
To give a bit more context, the string is coming from the server side. It was originally a python datetime object which had been shoved into a JSON object and sent clientside - so I'm confident the string will always be of that form. Logic Ali's method (although a little less sophisticated) has won the day. I initially did try converting to a Date object, however couldn't seem to get that to give me sensible answers.