According to http://www.codingforums.com/archive/index.php/t-98569.html, the date validation could be done using the javascript’s date object.
I’ve a similar scenario, where I have individual year,month,date in seperate text boxes which get validated by regular expressions.Now I would like to leverage the JS’s date object to check stuff like days in a month and leap year validation which are not done by RegExp validation. But the stuff discussed in the above link doesn’t quite work for me.
For example,
<script type="text/javascript">
var dy= new Date(2001,2,30);
alert(dy.getFullYear()+" "+dy.getMonth()+" "+dy.getDate());
</script>
returns the date as it is. Shouldn’t dy.getMonth() return something like -1 to show that 30 days doesn’t exist in the month of February?. If this isn’t possible using Date object, please suggest some alternatives to validate the date.
Update:
I just found another link(http://internotredici.com/article/checkdateinjavascript/) which says the same.
PS:I am working on JS1.2 which is pretty old.
You can make the date from the day, month, year bits, and then check that the bits are correct.