How to specify a minimum value to limit fractionDigits in an XML schema?

I have the 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 it possible to specify a minimum quantity of xsd:fractionDigits2? Since I have the following salary limit:, positive number with 2 decimal places precision, e.g. 10000.50and the validation should occur with errors on inputs of type 1000.5452or 14582.0001, as well as on input 1000.5or 10000.

PS: Using XML Schema 1.0

+4
source share
1 answer

You can add a template constraint:

<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 value provided must match the regular expression.

fractionDigits, .

+6

Source: https://habr.com/ru/post/1532680/


All Articles