指定字符串长度范围的RegEx:XSD属性元素



我试图将架构的属性元素的长度限制在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的区间=>end-point code is lower than the start-point code

您也可以使用xs:maxLengthxs:minLength:

<xsd:restriction base="xsd:string">
  <xsd:minLength value="3"/>
  <xsd:maxLength value="20"/>
</xsd:restriction>

最新更新