Comparing date fields in case of leap years
<p>I want to compare two date fields.. I have gotten pretty close and it even works fine..</p>

<p>But problem comes when "ToDate" field is a </p>

<pre><code>leap year&gt;= "FromDate"
</code></pre>

<p>For eg:</p>

<pre><code>from date= 29/02/1996
to date= 29/02/1996
to date= 29/02/1992
to date= 29/02/1995
</code></pre>

<p>the code works fine..</p>

<p>But if  </p>

<pre><code>from date= 29/03/1996
to date= 29/02/1996
</code></pre>

<p>the code fails...</p>

<p>this is my code</p>

<pre><code>function isDate(value)
{
    var fromDate = document.getElementById("fromDate").value
    var toDate= document.getElementById("toDate").value
    var dateRegEx = null;
    dateRegEx = new RegExp(/^(((0[1-9]|[12]\d|3[01])\/(0[13578]|1[02])\/((19|[2-9]\d)\d{2}))|((0[1-9]|[12]\d|30)\/(0[13456789]|1[012])\/((19|[2-9]\d)\d{2}))|((0[1-9]|1\d|2[0-8])\/02\/((19|[2-9]\d)\d{2}))|(29\/02\/((1[6-9]|[2-9]\d)(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00))))$/g);

    if (dateRegEx.test(fromDate)){
    }
    else{
        alert("Invalid from date");
        return false;
    }
    dateRegEx = new RegExp(/^(((0[1-9]|[12]\d|3[01])\/(0[13578]|1[02])\/((19|[2-9]\d)\d{2}))|((0[1-9]|[12]\d|30)\/(0[13456789]|1[012])\/((19|[2-9]\d)\d{2}))|((0[1-9]|1\d|2[0-8])\/02\/((19|[2-9]\d)\d{2}))|(29\/02\/((1[6-9]|[2-9]\d)(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00))))$/g);
    if(dateRegEx.test(toDate)) {
    }
    else{
        alert("Invalid to date");
        return false;
    }
    var stDate = new Date(fromDate);
    var enDate = new Date(toDate);
    var compDate = enDate - stDate;

    if(compDate &gt; 0)
        return true;
    else
    {
        alert("Please Enter the correct date ");
        return false;
    }
    /**/
}
</code></pre>

<p>how to make it work for all leap years...where would i have to make changes in the code.</p>
