2012-01-20 24 views
2

我試圖限制模式的屬性元素長度在3到20個字符之間,但我收到錯誤說我的RegEx無效:正則表達式指定的字符串長度範圍:XSD屬性元素

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

回答

4

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

+0

哦,哇,我什至沒有注意到第二個z是大寫字母,感謝你借給我你的眼睛,並指出了我。 :) –

1

您也可以使用xs:maxLengthxs:minLength

<xsd:restriction base="xsd:string"> 
    <xsd:minLength value="3"/> 
    <xsd:maxLength value="20"/> 
</xsd:restriction> 
相關問題