XSD maxLength and minLength applied to integer
Asked Answered
K

2

5

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>
Kucera answered 22/1, 2017 at 18:11 Comment(0)
C
6

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.

Cataract answered 22/1, 2017 at 18:30 Comment(2)
maybe you can help me with this also the field above is about a date time but without any slashes or other symbols is it still possible to check if it is a date?Kucera
You can use regular expressions or assertions to get part way there, but really you should use xs:date directly because the interoperability benefits of ISO 8601 compliance will far outweigh those of following any other idiosyncratic date formatting preferences you might have.Cataract
M
4

Looking at https://www.w3.org/TR/xmlschema-2/#integer you can specify the totalDigits as 14 to have something similar to maxLength as 14. You can also specify minInclusive as 100000000000.

Mediation answered 22/1, 2017 at 18:24 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.