如何在XML Schema中为fractionDigits限制指定最小值? [英] How to specify minimal value for fractionDigits restriction in XML Schema?

查看:255
本文介绍了如何在XML Schema中为fractionDigits限制指定最小值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下XML模式:

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

是否可以选择将xsd:fractionDigits的最小数量指定为2?因为我对薪水有以下限制:positive number with 2 decimal places precision, e.g. 10000.50并且对1000.545214582.0001之类的输入应该进行验证,但对于输入1000.510000的验证也应失败.

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:使用XML Schema 1.0

PS: Using XML Schema 1.0

推荐答案

您可以添加模式限制:

<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.

在这一点上,您可能也可以摆脱fragmentDigits元素,因为该约束已由正则表达式覆盖.

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

这篇关于如何在XML Schema中为fractionDigits限制指定最小值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆