title: Prevent future date and today date using custom validator
body: <p>I'm developing a project using <strong>Entity framework</strong> in <code>.NET 4</code>. There is a page for sign up which has a field of date of birth. I want to validate it so that date of birth cant be in future or today. Moreover if it could be 5 years back as compared today. </p>
  
  <p>Here is my code.</p>
  
  <pre><code>Date of Birth:
  &lt;asp:RequiredFieldValidator ID="rfv_txtbx_DOB" runat="server" ControlToValidate="txtbx_DOB" CssClass="validator" Display="Dynamic" ErrorMessage="Date of Birth Required" SetFocusOnError="True" Text="*" ValidationGroup="vg" /&gt;
  &lt;asp:CustomValidator ID="cv_txtbx_DOB" runat="server"  ControlToValidate="txtbx_DOB" CssClass="validator" Display="Dynamic" 
      ErrorMessage="Date of Birth cannot be today or in future" SetFocusOnError="True" Text="*" ValidationGroup="vg" ClientValidationFunction="validateDate"/&gt;
  &lt;asp:TextBox ID="txtbx_DOB" runat="server" CssClass="txtbx" Width="200px" /&gt;
  &lt;ajaxToolkit:CalendarExtender ID="txtbx_DOB_CalendarExtender" runat="server" Enabled="True" Format="dd-MM-yyyy" TargetControlID="txtbx_DOB" /&gt;
  &lt;script language="javascript" type="text/javascript"&gt;
      function Validate(sender, args) {
          var currentDate = new Date().getDate();
  
              if (args.Value &lt; currentDate)
                  args.IsValid = true;
              else
                  args.IsValid = false;
          }
  &lt;/script&gt;
  </code></pre>