Date Validation not working using JavaScript
<p>I have two two date fields - from date and to date, and i need to validate 3 things</p>

<ul>
<li>Both the values are entered or not</li>
<li>Date datatype check </li>
<li>To date must be greater than from date.</li>
</ul>

<p>But my script is not working.</p>

<p>can some body please check?</p>

<p>Thanks</p>

<pre><code> function checkBothDates(sender,args)
{
    var from = document.getElementById(sender.From);
    var to = document.getElementById(sender.To);
    var behaviorId =  sender.behavior;
    var from_value = from.value;
    var to_value = to.value; 

    if((from_value == "")&amp;&amp;(to_value == ""))
    {
         args.IsValid = true;
    }
    else
    {
        if((from_value != "")&amp;&amp;(to_value != ""))
        {                       
               if((isValidDate(from_value))&amp;&amp;(isValidDate(to_value)))
               {
                    if(from_value &lt; to_value)
                    {
                         args.IsValid = false; 
                          sender.errormessage = "To date must be greater than or equal to the from date"; 
                    }
               }
               else
               {
                    args.IsValid = false;                
                    sender.errormessage = "Please enter valid dates in both the fields";
                    if(behaviorId != null)
                    {
                       openCollapsiblePanel(behaviorId);
                    }        
               }
        }
        else
        {
            args.IsValid = false;                
            sender.errormessage = "Please make sure you enter both the values";
            if(behaviorId != null)
            {
               openCollapsiblePanel(behaviorId);
            }        
        }
    }
}

function isValidDate(val)
{

        var format = 'dd/MM/yyyy'
        var regexp = /^\d{1,2}\/\d{1,2}\/\d{4}$/;                       
        if (!regexp.test(val)) 
        {
           return false;
        }
        else 
        {
           try
            {
                $.datepicker.parseDate(format,val,null);
                return true;                    
            }
            catch(Error)
            {
               return false;                    
            }
        }
}
</code></pre>
