4

I'm trying to restrict an attribute element of a schema to be between 3 and 20 characters long, but I'm getting an error saying my RegEx is invalid:

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

Any idea what I'm doing incorrectly here? Specific error is "Range end code point is less than the start end code point"

Deduplicator
  • 44,692
  • 7
  • 66
  • 118
Chris V.
  • 1,123
  • 5
  • 22
  • 50

2 Answers2

6

a-Z is the invalid range, you should use the lowercase z instead a-z

 <xs:pattern value="[A-Za-z]{3,20}" />

Note that a ascii value is 97 and Z is 90 so you were actually defining an interval from 97 to 90 => end-point code is lower than the start-point code

Roberto Decurnex
  • 2,514
  • 1
  • 19
  • 28
  • Oh wow I didn't even notice that second z was uppercase, thanks for lending me your eyes and pointing that out for me. :) – Chris V. Jan 20 '12 at 17:34
2

You could also use xs:maxLength and xs:minLength:

<xsd:restriction base="xsd:string">
  <xsd:minLength value="3"/>
  <xsd:maxLength value="20"/>
</xsd:restriction>
Daniel Haley
  • 51,389
  • 6
  • 69
  • 95