
My form return value like (2011-10-05)yyyy-mm-dd ... my End date greater than my start date.. How to do validation in javascript ?

<html>
<head>
<script language="JavaScript">
function checkdate(date1,date2){
var validformat=/^\d{4}\-\d{2}\-\d{2}$/
var returnval=false
if(!validformat.test(date1.value)){
alert("Invalid Date 1");
document.form.date1.value="";
}
else if(!validformat.test(date2.value)){
alert("Invalid Date 2");
document.form.date2.value="";
}
else{
var start = document.form.date1.value;
var end = document.form.date2.value;
var stDate = new Date(start);
var enDate = new Date(end);
var compDate = enDate - stDate;
if(compDate >= 0)
return true;
else
{
alert("End date should be greater than start date.");
return false;
}
}
}
</script>
</head>
<form name="form">
<table>
<tr><td>Enter Start Date:</td><td><input type="text" name="date1" ></td></tr>
<tr><td>Enter End Date:</td><td><input type=text name="date2" ></td></tr>
<tr><td><input type="button" onClick="checkdate(this.form.date1, this.form.date2);" value="Check Date"></td></tr>
</table>
</form>
</html>
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.