1

Currently I have an Xsd validating with this rule

<xs:simpleType name='shipTo'>
    <xs:restriction base='xs:string'>
        <xs:minLength value='6'/>
    </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>

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Yeah, that would make more sense. Unfortunately, I don't control the consumer of said xml...which is not written well.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.