How to specify minimal value for fractionDigits restriction in XML Schema?
Asked Answered
S

1

8

I have a following XML Schema:

<xsd:simpleType name="fractionalSalary">
    <xsd:restriction base="xsd:decimal">
        <xsd:fractionDigits value="2" />
        <xsd:minExclusive value="0" />
    </xsd:restriction>
</xsd:simpleType>

Is there any option to specify minimal number of xsd:fractionDigits to 2? Because I have a following restriction for salary: positive number with 2 decimal places precision, e.g. 10000.50 and validation should fail on inputs like 1000.5452 or 14582.0001 but also on input 1000.5 or 10000.

PS: Using XML Schema 1.0

Scott answered 20/3, 2014 at 14:41 Comment(1)
That's an exact number of fractional digits, not minimal.Hemispheroid
M
13

You can add a pattern restriction:

<xsd:simpleType name="fractionalSalary">
    <xsd:restriction base="xsd:decimal">
        <xsd:fractionDigits value="2" />
        <xsd:minExclusive value="0" />
        <xsd:pattern value="\d+\.\d{2}" />
    </xsd:restriction>
</xsd:simpleType>

This means that the decimal supplied must match the regex.

At this point, you can probably get rid of the fractionDigits element too, as that constraint is covered by the regex.

Martie answered 20/3, 2014 at 15:3 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.