I'm trying to write an XML Schema datatype for an element that must contain four alphanumerics (uppercase only), but not the all-digit combinations.
Stated in other words, a sequence of four of A-Z or 0-9, containing at least one of A-Z.
It's the latter part I'm having difficulty with, the "at least one" or "but not".
I've thought of and/or tried:
character class subtraction (but I think that there's no way to define the "classes" here?)
<!-- no example -->
combining 2 xs:restrictions
<xs:restriction>
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:pattern value="[0-9A-Z]{4}"/>
</xs:restriction>
</xs:simpleType>
<xs:pattern value="[^(\d\d\d\d)]"/>
</xs:restriction>
combining 2 xs:patterns in two datatypes
<xs:simpleType name="4alpha-at-least-one-letter">
<xs:restriction base="my-namespace:FourAlphanumericsType">
<xs:pattern value="[^(\d\d\d\d)]"/>
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="FourAlphanumericsType">
<xs:restriction base="xs:string">
<xs:pattern value="[0-9A-Z]{4}"/>
</xs:restriction>
</xs:simpleType>
I guess these are all dead ends, and I'm either missing something in the regular expression world, or XML regex is maybe not the best way to do this?
Given that the length is fixed, another simple solution is to combine xs:pattern and xs:length restrictions:
<xs:simpleType name="x">
<xs:restriction base="xs:string">
<xs:pattern value="[A-Z0-9]*[A-Z][A-Z0-9]*"/>
<xs:length value="4"/>
</xs:restriction>
</xs:simpleType>