我试图将模式的属性元素限制在 3 到 20 个字符之间,但我收到一条错误消息,指出我的 RegEx 无效:
<xs:attribute name="name" use="required">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:pattern value="[A-Za-Z]{3,20}" />
</xs:restriction>
</xs:simpleType>
</xs:attribute>
知道我在这里做错了什么吗?具体错误是"Range end code point is less than the start end code point"
最佳答案
a-Z
是无效范围,您应该使用小写的 z
而不是 a-z
<xs:pattern value="[A-Za-z]{3,20}" />
请注意,a
ascii 值为 97,Z
为 90,因此您实际上定义了从 97 到 90 的间隔 => 终点代码较低比起点代码
关于指定字符串长度范围的 RegEx : XSD attribute element,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8945410/