I have an HTML page that has several fields and one of them is to select DateTime using jquery plugin, which lets user to select DateTime like : 2011-06-05 07:10 or 2011-03-05 11:10 etc.My problem is how do I validate this field value before posting it to server.I want to use javascript to ensure that the field value is only DateTime in this format and is not a invalid value like "2231" or "afaf".
I have an HTML page that has several fields and one of them is
Share
You MUST validate on the server too.
The simplest way on the client to test a date string like that is to use Date.parse like this (I am not testing the format other than using date parse. If the user enters another format, you will need to test that too)
This is of course completely unnecessary if you use a widget to create the date.