title: Greater Than or Equal To Today Date validation annotation in MVC3
body: <p>Has anyone seen an MVC3 data annotation for Date validation that requires a single selected date to be equal to or greater than current date?</p>
  
  <p>If there's already a third party add on that's cool too. I'm already using the DataAnnotationsExtensions but it doesn't offer what I'm looking for. </p>
  
  <p>There doesn't seem to be any reference of this on. So, hoping someone has already solved this before I try to reinvent the wheel and write my own custom validator. </p>
  
  <p>I've tried <code>Range</code> but that requires 2 dates and both have to be constants in string format such as <code>[Range(typeof(DateTime), "1/1/2011", "1/1/2016")]</code> but that doesn't help. And the DataAnnotationsExtensions <code>Min</code> validator only accepts <code>int</code> and <code>double</code></p>
  
  <hr>
  
  <p><strong>Update</strong> Solved</p>
  
  <p>Thanks to @BuildStarted this is what I ended up with and it works great server-side and now client side with my script</p>
  
  <hr>
  
  <pre class="lang-cs prettyprint-override"><code>using System;
  using System.Collections.Generic;
  using System.ComponentModel.DataAnnotations;
  using System.Web.Mvc;
  
  namespace Web.Models.Validation {
  
      [AttributeUsage(AttributeTargets.Field | AttributeTargets.Property, AllowMultiple = false, Inherited = true)]
      public sealed class DateMustBeEqualOrGreaterThanCurrentDateValidation : ValidationAttribute, IClientValidatable {
  
          private const string DefaultErrorMessage = "Date selected {0} must be on or after today";
  
          public DateMustBeEqualOrGreaterThanCurrentDateValidation()
              : base(DefaultErrorMessage) {
          }
  
          public override string FormatErrorMessage(string name) {
              return string.Format(DefaultErrorMessage, name);
          }  
  
          protected override ValidationResult IsValid(object value, ValidationContext validationContext) {
              var dateEntered = (DateTime)value;
              if (dateEntered &lt; DateTime.Today) {
                  var message = FormatErrorMessage(dateEntered.ToShortDateString());
                  return new ValidationResult(message);
              }
              return null;
          }
  
          public IEnumerable&lt;ModelClientValidationRule&gt; GetClientValidationRules(ModelMetadata metadata, ControllerContext context) {
              var rule = new ModelClientCustomDateValidationRule(FormatErrorMessage(metadata.DisplayName));
              yield return rule;
         }
      }
  
      public sealed class ModelClientCustomDateValidationRule : ModelClientValidationRule {
  
          public ModelClientCustomDateValidationRule(string errorMessage) {
              ErrorMessage = errorMessage;
              ValidationType = "datemustbeequalorgreaterthancurrentdate";
          }
      }
  }
  </code></pre>
  
  <p>And in my model</p>
  
  <pre class="lang-cs prettyprint-override"><code>[Required]
  [DateMustBeEqualOrGreaterThanCurrentDate]
  public DateTime SomeDate { get; set; }
  </code></pre>
  
  <p>The client side script</p>
  
  <pre class="lang-java prettyprint-override"><code>/// &lt;reference path="jquery-1.7.2.js" /&gt;
  
  jQuery.validator.addMethod("datemustbeequalorgreaterthancurrentdate", function (value, element, param) {
      var someDate = $("#SomeDate").val();
      var today;
      var currentDate = new Date();
      var year = currentDate.getYear();
      var month = currentDate.getMonth() + 1;  // added +1 because javascript counts month from 0
      var day = currentDate.getDate();
      var hours = currentDate.getHours();
      var minutes = currentDate.getMinutes();
      var seconds = currentDate.getSeconds();
  
      today = month + '/' + day + '/' + year + '  ' + hours + '.' + minutes + '.' + seconds;
  
      if (someDate &lt; today) {
          return false;
      }
      return true;
  });
  
  jQuery.validator.unobtrusive.adapters.addBool("datemustbeequalorgreaterthancurrentdate");
  </code></pre>