How to define a varying length of the string in XSD pattern?

Posted by infant programmer on Stack Overflow See other posts from Stack Overflow or by infant programmer
Published on 2010-04-15T08:41:30Z Indexed on 2010/04/15 8:43 UTC
Read the original article Hit count: 292

Filed under:
|

The input XML tag must be validated for a pattern which is like this:

type : positive int / decimal, minimum length is 0, max length is 12(before decimal point), fraction digits are optional if exist then precision must be 2. This means both positive integer and Decimal numbers(2 digit precision) are allowed.

so the acceptable values can be like,
null, 0, 0.00, 1234567890, 123456789012, 123456789012.12,

invalid values are:
0.000, 1234567890123(13 digits - invalid),

The pattern I have designed is:

<xs:pattern value="|([0-9]){12}|([0-9]){12}[.][0-9][0-9]"/>

The problem with this pattern is, it doesn't allow the number with string-length less than 12, it says "1234567890" is an invalid value, where as it must be allowed!

© Stack Overflow or respective owner

Related posts about xsd

Related posts about xml-schema