加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

xml – XSD架构:如何指定值中的位数?

发布时间:2020-12-16 23:10:47 所属栏目:百科 来源:网络整理
导读:我想将元素中允许的位数限制为6: AccountNumber123456/AccountNumberAccountNumber999999/AccountNumberAccountNumber000000/AccountNumber 字段格式规范是6位数,零填充,数字. i read that i might want to use totalDigits限制,基于: totalDigits Specifi
我想将元素中允许的位数限制为6:

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读