ASPForums.Net RSS Feedhttp://www.aspforums.net/Handlers/RSS.ashxLatest additions to the content that appears on ASPForums.Net(c) 2019 www.aspforums.com. All rights reserved.Date and Time validation using RegularExpression and CustomValidator in ASP.Net<p>Hi <a class="username" rel="nauna">nauna</a>,</p> <p>Check this example. Now please take its reference and correct your code.</p> <p><strong><span style="text-decoration: underline;">HTML</span></strong></p> <pre class="brush: html">&lt;div&gt; &lt;asp:TextBox ID=&#34;txtDate1&#34; runat=&#34;server&#34; /&gt; &lt;asp:Button ID=&#34;Button1&#34; Text=&#34;Validate&#34; runat=&#34;server&#34; ValidationGroup=&#34;Group1&#34; /&gt; &lt;br /&gt; &lt;asp:RegularExpressionValidator ID=&#34;RegularExpressionValidator1&#34; runat=&#34;server&#34; ControlToValidate=&#34;txtDate1&#34; ValidationExpression=&#34;(((0|1)[0-9]|2[0-9]|3[0-1])\/(0[1-9]|1[0-2])\/((19|20)\d\d) [0-2][0-9]:[0-5][0-9])$&#34; ErrorMessage=&#34;Invalid format. Valid format is dd/MM/yyyy HH:mm&#34; ForeColor=&#34;Red&#34; Display=&#34;Dynamic&#34; ValidationGroup=&#34;Group1&#34; /&gt; &lt;br /&gt; &lt;asp:CustomValidator ID=&#34;CustomValidator1&#34; runat=&#34;server&#34; ErrorMessage=&#34;DateTime should be equal or greater than current DateTime&#34; ForeColor=&#34;Red&#34; ControlToValidate=&#34;txtDate1&#34; ClientValidationFunction=&#34;DateTimeValidation&#34; Display=&#34;Dynamic&#34; ValidationGroup=&#34;Group1&#34;&gt;&lt;/asp:CustomValidator&gt; &lt;/div&gt; &lt;script type=&#34;text/javascript&#34;&gt; function DateTimeValidation(sender, args) { var enteredValue = document.getElementById(&#34;&lt;%=txtDate1.ClientID %&gt;&#34;).value; var date = enteredValue.split(&#39;/&#39;)[0]; var month = enteredValue.split(&#39;/&#39;)[1]; var year = enteredValue.split(&#39;/&#39;)[2].split(&#39; &#39;)[0]; var enteredDateTime = new Date(month + &#34;/&#34; + date + &#34;/&#34; + year + &#34; &#34; + enteredValue.split(&#39; &#39;)[1]); var currentDateTime = new Date(); if (enteredDateTime &gt;= currentDateTime) { args.IsValid = true; } else { args.IsValid = false; } } &lt;/script&gt;</pre> <p><strong><span style="text-decoration: underline;">Screenshot</span></strong></p> <p><img src="https://imgur.com/M5uhQVN.gif" alt="" width="441" height="138" /></p>https://www.aspforums.net:443/Threads/170771/Date-and-Time-validation-using-RegularExpression-and-CustomValidator-in-ASPNet/https://www.aspforums.net:443/Threads/170771/Date-and-Time-validation-using-RegularExpression-and-CustomValidator-in-ASPNet/Mon, 01 Oct 2018 06:13:21 GMT