title: Hibernate validator constraints in XML
body: <p>I am using xml file to specify my constraints on an incoming request bean. I do this in a validation-constraints.xml file as follows: </p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;constraint-mappings xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://jboss.org/xml/ns/javax/validation/mapping validation-mapping-1.0.xsd"
      xmlns="http://jboss.org/xml/ns/javax/validation/mapping"&gt;
      &lt;default-package&gt;com.mathworks.internal.business.geoTypes
      &lt;/default-package&gt;
  
      &lt;bean class="GetStatesByCountryCodeRequest"&gt;
          &lt;field name="countryCode"&gt;
              &lt;constraint annotation="org.hibernate.validator.constraints.NotBlank" /&gt;
  
          &lt;/field&gt;
      &lt;/bean&gt;
  
  &lt;/constraint-mappings&gt;
  </code></pre>
  
  <p>I also need the countryCode to be only 2 characters long. I looked at the length validator provided by hibernate but it requires a min and a max value which I am guessing in my case should be 2 and 2. How can I specify the length constraint in a XML way? I cannot find any examples for that.</p>