title: Spring Validation: Requiring an exact length on an optional field
body: <p>In Spring MVC, I'm attempting to use annotations to perform validation of form input.  I have some fields that are optional, but when input is provided, it must meet certain criteria.  For example, I have one field that can be left blank, but when it is filled in, the answer must be exactly five characters long.</p>
  
  <p>I've tried things like </p>
  
  <pre><code>@Size(min=5, max=5)
  private String value;
  </code></pre>
  
  <p>but that gives the user an error if the user doesn't fill in the field.</p>
  
  <p>How can I provide some "rules" for an optional field?</p>