Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If you're using ASP.NET, you can use an ASP.NET Compare Validator [<a href="http://blogs.mgtechgroup.com/markc/archive/2007/06/07/ASP.NET-Date-Validator.aspx" rel="nofollow noreferrer">ASP.NET Date Validator</a>].</p> <pre><code>&lt;asp:TextBox ID="tb" runat="server"&gt;&lt;/asp:TextBox&gt; &lt;asp:CompareValidator ID="cv" runat="server" ControlToValidate="tb" ErrorMessage="* Please enter a valid date!" Text="*" Operator="DataTypeCheck" Type="Date"&gt;&lt;/asp:CompareValidator&gt; </code></pre> <p>**** Update**</p> <p>I took the javascript that was executed by the Compare Validator above and wrapped a custom jQuery Validation method around it:</p> <pre><code>&lt;script type="text/javascript"&gt; $(document).ready(function () { $.validator.addMethod("truedate", function (value, element, params) { function GetFullYear(year, params) { var twoDigitCutoffYear = params.cutoffyear % 100; var cutoffYearCentury = params.cutoffyear - twoDigitCutoffYear; return ((year &gt; twoDigitCutoffYear) ? (cutoffYearCentury - 100 + year) : (cutoffYearCentury + year)); } var yearFirstExp = new RegExp("^\\s*((\\d{4})|(\\d{2}))([-/]|\\. ?)(\\d{1,2})\\4(\\d{1,2})\\.?\\s*$"); try { m = value.match(yearFirstExp); var day, month, year; if (m != null &amp;&amp; (m[2].length == 4 || params.dateorder == "ymd")) { day = m[6]; month = m[5]; year = (m[2].length == 4) ? m[2] : GetFullYear(parseInt(m[3], 10)); } else { if (params.dateorder == "ymd") { return null; } var yearLastExp = new RegExp("^\\s*(\\d{1,2})([-/]|\\. ?)(\\d{1,2})(?:\\s|\\2)((\\d{4})|(\\d{2}))(?:\\s\u0433\\.)?\\s*$"); m = value.match(yearLastExp); if (m == null) { return null; } if (params.dateorder == "mdy") { day = m[3]; month = m[1]; } else { day = m[1]; month = m[3]; } year = (m[5].length == 4) ? m[5] : GetFullYear(parseInt(m[6], 10)); } month -= 1; var date = new Date(year, month, day); if (year &lt; 100) { date.setFullYear(year); } return (typeof (date) == "object" &amp;&amp; year == date.getFullYear() &amp;&amp; month == date.getMonth() &amp;&amp; day == date.getDate()) ? date.valueOf() : null; } catch (err) { return null; } }, "Please enter an actual date."); $("#form1").validate(); $("#one").rules('add', { truedate: { cutoffyear: '2029', dateorder: 'mdy' } }); }); &lt;/script&gt; &lt;input id="one" /&gt; </code></pre>
    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.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. 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