开发者

Xsd, Validate empty or minimum length string

Currently I have an Xsd validating with this rule

<xs:simpleType name='shipTo'>
    <xs:restriction base='xs:string'>
        <xs:minLength value='6'开发者_C百科/>
    </xs:restriction>
</xs:simpleType>

I need to allow blanks as well, but if a value is entered, it's minimum length should still be 6.

Can I do this without resorting to this xs:pattern and regex?

<xs:simpleType name='shipTo'>
    <xs:restriction base='xs:string'>
        <xs:pattern value='^(?:|[\w]{6,})$'/>
    </xs:restriction>
</xs:simpleType>


The regex will work, but you should really make the element that you will be assigning shipTo to optional, and not include it in the XML file if it has no value.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜