Johnston
Johnston

Reputation: 2873

Having two different types for creating an XML schema

Hi i am working on making a basic shipping xml schema and i was wondering if there was a way to have the schema restrictions to work for both canadian and american postal codes:

 <xs:simpleType name="postalCode">
<xs:restriction base="xs:string" >
  <xs:pattern value="\d{3}-\d{3}"/>
</xs:restriction>

is there a way to have an "or" in there so i could have the american postal code of just numbers work aswell?

Any comments or suggestions are appreciated. Thanks

Upvotes: 2

Views: 51

Answers (1)

Grzegorz Szpetkowski
Grzegorz Szpetkowski

Reputation: 37904

Try with | character to provide second (OR) option in your pattern e.g. (additional parentheses aren't necessary in here):

<xs:simpleType>
    <xs:restriction base="xs:string" >
        <xs:pattern value="\d{3}-\d{3}|\d{5}"/>
    </xs:restriction>
</xs:simpleType>

Upvotes: 1

Related Questions