XSD 架构:如何指定值中的位数? [英] XSD schema: How to specify the number of digits in a value?
本文介绍了XSD 架构:如何指定值中的位数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想将元素中允许的位数限制为 6:
i want to limit the number of digits allowed in an element to 6:
<AccountNumber>123456</AccountNumber>
<AccountNumber>999999</AccountNumber>
<AccountNumber>000000</AccountNumber>
字段格式规范为 6 位、零填充、数字.
The field format specification is 6-digit, zero-padded, numeric.
我读到我可能想使用 totalDigits
限制,基于:
totalDigits
指定允许的确切位数.必须大于零
totalDigits
Specifies the exact number of digits allowed. Must be greater than zero
所以我有简单的类型:
<xs:simpleType name="AccountNumber">
<xs:restriction base="xs:int">
<xs:totalDigits value="6"/>
</xs:restriction>
</xs:simpleType>
当它捕获无效数字时,例如:
And while it catches invalid numbers, such as:
<AccountNumber>1234567</AccountNumber>
<AccountNumber>0000000</AccountNumber>
<AccountNumber></AccountNumber>
它不会捕获无效数字:
<AccountNumber>12345</AccountNumber>
<AccountNumber>01234</AccountNumber>
<AccountNumber>00123</AccountNumber>
<AccountNumber>00012</AccountNumber>
<AccountNumber>00001</AccountNumber>
<AccountNumber>00000</AccountNumber>
<AccountNumber>0000</AccountNumber>
<AccountNumber>000</AccountNumber>
<AccountNumber>00</AccountNumber>
<AccountNumber>0</AccountNumber>
指定允许的确切位数的建议限制是什么?
What is a suggested restriction to specify the exact number of digits allowed?
推荐答案
您需要使用 xs:pattern
并提供正则表达式以将其限制为数字.
You need to use xs:pattern
and provide a regular expression to limit it to a number.
<xs:simpleType name="AccountNumber">
<xs:restriction base="xs:int">
<xs:pattern value="\d{6}"/>
</xs:restriction>
</xs:simpleType>
这篇关于XSD 架构:如何指定值中的位数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文