title: JSR 303 - javax.validation - Validate a date
body: <p>I have a Java EE application and I want to validate a Date.
  With a String I do this:</p>
  
  <pre><code>import javax.validation.constraints.NotNull;
  import javax.validation.constraints.Size;
  ...
  @NotNull
  @Size(min = 1, max = 255)
  private String myString;
  </code></pre>
  
  <p>But now I have two dates which I want to validate. The user can in the frontend system write a String in a text field which will be transferred via JSON (I have to use text field, I can not use a datepicker).</p>
  
  <p>So my backend does have this in my domain class:</p>
  
  <pre><code>@DateTimeFormat(pattern = "dd.MM.yy")
  @Temporal(value=TemporalType.TIMESTAMP)
  private Date myStartDate;
  
  @DateTimeFormat(pattern = "dd.MM.yy")
  @Temporal(value=TemporalType.TIMESTAMP)
  private Date myEndDate;
  </code></pre>
  
  <p>I want to validate against the format "dd.MM.yyyy". How can this be done?</p>
  
  <p>And, I do not think so, but is there an automatic validation to check if the start date is before the end date? I only found <code>@Future</code> and <code>@Past</code>.</p>
  
  <p>So the only solution is to use a @Pattern, a regular expression?!</p>
  
  <p>Thank you in advance for your help, Best Regards.</p>