Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can use a JavaScript validation library, which uses the HTML5 input attributes like min and max: for example <a href="http://jqueryvalidation.org/documentation/" rel="nofollow">jQuery Validation</a>:</p> <pre><code>&lt;input id="mydate" name="mydate" type="date" min="2000-01-01" max="2010-31-12" required /&gt; &lt;script&gt; $("#mydate").validate(); &lt;/script&gt; </code></pre> <p>Have a look as this fiddle for a working example: <a href="http://jsfiddle.net/a5Mvt/1/" rel="nofollow">http://jsfiddle.net/a5Mvt/1/</a></p> <p>In addition you might want to use a library like <a href="http://modernizr.com/" rel="nofollow">Modernizr</a> to check for browser support of <code>input[type="date"]</code> and use a datepicker control from <a href="http://jqueryui.com/datepicker/" rel="nofollow">jQuery UI</a> or something similar, if it is not supported.</p> <hr> <p><strong>Update:</strong> Here's a version, that doesn't use jQuery or any other additional library:</p> <pre><code>&lt;input id="mydate" name="mydate" type="date" min="2000-01-01" max="2010-31-12" required /&gt; &lt;span id="mydate_error" style="display:none;"&gt;&lt;/span&gt; &lt;script&gt; var mydate = document.getElementById('mydate'), mydateError = document.getElementById('mydate_error'); mydate.addEventListener('input', function() { if (!mydate.value.match(/\d{4}-\d{1,2}-\d{1,2}/)) { mydateError.innerHTML = 'Please specify a valid date in the form 1990-02-22'; mydateError.style.display = 'inherit'; } else { var value = new Date(mydate.value), min = new Date(mydate.min), max = new Date(mydate.max); if (value &lt; min || value &gt; max) { mydateError.innerHTML = 'Date has to be between ' + min.toDateString() + ' and ' + max.toDateString(); mydateError.style.display = 'inherit'; } else { mydateError.style.display = 'none'; } } }); &lt;/script&gt; </code></pre> <p>Updated fiddle: <a href="http://jsfiddle.net/a5Mvt/2/" rel="nofollow">http://jsfiddle.net/a5Mvt/2/</a></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload