title: jQuery Date Format Validation (Highlight The Text Field)
body: <p>I have a date textbox on an html page. I want to validate it on run time using jQuery for the format dd-mm-yyyy. If the enter the invalid format the textbox background should turn red.</p>
  
  <p>I'm using the following but failed to do so.</p>
  
  <pre><code>&lt;script&gt;
  jQuery(document).ready(function(){
   jQuery('#submit').click(function () {
    var dateReg = /^\d{2}\-\d{2}\-\d{4}$/;
  
    if(!dateReg.test(date.val())){
      date.addClass('highlight');
      jQuery(date).focus();
      return false;
    } else date.removeClass('highlight');
  }); 
  });
  &lt;/script&gt;
  
  &lt;style&gt;
      .highlight { background: #FFE6E7; }
  &lt;/style&gt;
  
  &lt;body&gt;
      &lt;form&gt;
      &lt;input type="text" name="date"/&gt; &lt;em&gt;(dd-mm-yyyy)&lt;/em&gt;&lt;br&gt;
      &lt;input type="submit" value="submit" id="submit"/&gt;
      &lt;/form&gt;
  &lt;/body&gt;
  </code></pre>
  
  <p>...</p>
  
  <p>I tried it but unable to achieve it :(
  Secondly I want it to be validate as soon as the user enters the value. Not onclick of submit.</p>
  
  <p>Can anyone please help me with this?</p>