@Size annotation to validate a field
<p>I need to validate a field - secPhoneNumber (secondary phone #). I need to satisfy below conditions using JSR validation</p>

<ul>
<li>The field can be empty/null</li>
<li>Otherwise, the data must be of length 10.</li>
</ul>

<p>I tried the code below. The field is always getting validated on form submission.  How do I validate the field to be of length 10 only when it is not empty?</p>

<p>Spring Form:</p>

<pre><code>&lt;form:label path="secPhoneNumber"&gt;
Secondary phone number &lt;form:errors path="secPhoneNumber" cssClass="error" /&gt;
&lt;/form:label&gt;
&lt;form:input path="secPhoneNumber" /&gt;
</code></pre>

<p>Bean</p>

<pre><code>@Size(max=10,min=10)
    private String secPhoneNumber;
</code></pre>