<xsd:element name="CurrencyCode" minOccurs="0" type="xsd:string">
<xsd:simpleType>
<xsd:restriction>
<xsd:length value="3"/>
</xsd:restriction>
</xsd:simpleType>
</xsd:element>
I want my Currencycode to be an optional value and if at all there is a value it should have a length of 3 letters .. either my CurrencyCode can have Length=0 or length=3
When i use the 开发者_Python百科above code the validator returns an error when there is an empty field
So how can i deal with this ??
Have not tried this (do not have suitable env set up on this machine) but according to the specification you can do as follows:
<xsd:element name="CurrencyCode" minOccurs="0" type="xsd:string">
<xsd:simpleType>
<xsd:restriction base="xsd:string">
<xsd:pattern value="(?:^$|\w{3})"/>
</xsd:restriction>
</xsd:simpleType>
</xsd:element>
Regular expression (?:^$|\w{3})
matches either empty string or exactly three word characters. You can use (?:^$|[A-Z]{3})
in case you want to accept currency codes only in upper case.
精彩评论