I want to define an element in XML schema that will allow for an empty string or some specific pattern, e.g.,:
<Code/>
<Code></Code>
<Code> </Code>
<Code>11111</Code>
<Code>111111</Code> - INVALID
<Code>AAAAA</Code> - INVALID
How can I modify my existing restriction?
<xs:element name="Code">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:pattern value="[0-9]{5}" />
</xs:restriction>
</xs:simpleType>
</xs:element>
Add \s
as another choice to your regex to allow whitespace characters [#x20\t\n\r] (That is: "regular" space, tab, line feed, carriage return. Non-breaking space is not included.)
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:pattern value="\s*|[0-9]{5}" />
</xs:restriction>
</xs:simpleType>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With