I have following XSD element:
<xsd:element name="password">
<xsd:simpleType>
<xsd:restriction base="xsd:string">
<!-- Length check -->
<xsd:pattern value=".{9,12}" />
<!-- Format check -->
<xsd:pattern value=".*\d{2,}.*" />
<xsd:pattern value=".*[A-Z]{1,}.*" />
<xsd:pattern value=".*[a-z]{1,}.*" />
<xsd:pattern value=".*\p{Punct}.*" />
</xsd:restriction>
</xsd:simpleType>
</xsd:element>
I want to apply each of those patterns individually. It should first check that length is proper. If so then check that it has at least 2 digits and so on. Instead, it concatenates all the expressions together and tries to apply them together.
This is very poor design. If only one pattern is allowed <xsd:restriction>
should define the cardinality of <xsd:pattern>
to be 1. Allowing multiple <xsd:pattern>
gives the impression that multiple patterns are supported.
Is there a way to apply multiple patterns to a XSD element?
Multiple patterns per restriction are supported, but they do not mean AND; they mean OR:
Note: An XML
<restriction>
containing more than one<pattern>
element gives rise to a single ·regular expression· in the set; this ·regular expression· is an "or" of the ·regular expressions· that are the content of the<pattern>
elements.
If you want multiple regex constraints to apply concurrently, write them in a single <pattern>
.
For min/max length constraints, rather than using <pattern>
, consider using <minLength>
and <maxLength>
facets.
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