title: In ASP.NET MVC 4, how to validate that a DateTime value is entered on the correct format?
body: <p>In our ASP.NET MVC 4 application, one of the models has a field of the DateTime type. When editing such model objects via a form, the value for the DateTime field has to be non-empty and on the format <code>yyyy-MM-dd H:mm:ss</code> (e.g., 2012-10-17 10:49:00). How do I ensure this field is correctly validated in the application? I've tried the following annotations:</p>
  
  <pre><code>[System.ComponentModel.DataAnnotations.Required]
  [System.ComponentModel.DataAnnotations.DisplayFormat(DataFormatString="yyyy-MM-dd H:mm:ss",
          ApplyFormatInEditMode=true)]
  </code></pre>
  
  <p>However, validation of form data doesn't require all components of the format to be present. For instance, the value '2012-10-17' is accepted (leaving out the 'H:mm:ss' part). It's just verified that the field contains a valid DateTime string.</p>
  
  <p>How should I ensure that this DateTime field is indeed on my specified format (yyyy-MM-dd H:mm:ss)?</p>