XSD maxLength and minLength applied to integer

user3356007 picture user3356007 · Jan 22, 2017 · Viewed 8.2k times · Source

I am having some trouble finding out how to tell the XSD that the data of a field has to have an minimum length of 12 digits and a maximum length of 14 digits. Is there someone who knows how to do this because minlength and maxlength can only be used for strings.

<xs:simpleType name="timestamp_vorige_inspectie">
    <xs:restriction base="xs:integer">
        <xs:minLength value="12"/>
    </xs:restriction>
</xs:simpleType>

Answer

kjhughes picture kjhughes · Jan 22, 2017

You can use xs:pattern to restrict the number of digits to be in your range:

  <xs:simpleType name="timestamp_vorige_inspectie">
    <xs:restriction base="xs:integer">
      <xs:pattern value="\d{12,14}"/>
    </xs:restriction>
  </xs:simpleType>

\d is a regular expression construct that matches any digit. {12,14} specifies the allowed number of the preceding matches.