我想将元素中允许的位数限制为6: AccountNumber123456/AccountNumberAccountNumber999999/AccountNumberAccountNumber000000/AccountNumber 字段格式规范是6位数,零填充,数字. i read that i might want to use totalDigits限制
<AccountNumber>123456</AccountNumber> <AccountNumber>999999</AccountNumber> <AccountNumber>000000</AccountNumber>
字段格式规范是6位数,零填充,数字.
i read that i might want to use 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>
虽然它捕获无效数字,例如:
<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>
建议的限制是指定允许的确切位数?
您需要使用xs:pattern
并提供正则表达式以将其限制为数字.
<xs:simpleType name="AccountNumber"> <xs:restriction base="xs:int"> <xs:pattern value="\d{6}"/> </xs:restriction> </xs:simpleType>