Patterns using integers, reals etc.
1. | A few specific values |
To limit the available choices to, say, 3 integers, 1 2 or 3 <select>1</select> Use the following pattern
<element name="select">
<choice>
<value type="integer">1</value>
<value type="integer">2</value>
<value type="integer">3</value>
</choice>
</element>
The data type can be selected, fewer or more choices may be included. Equally valid integers such as 03 are accepted. | |
2. | A range of values |
When its required to validate that a value is contained between two limits, e.g. more than zero and less than 100, use the following pattern
<element name="rng">
<data type="float">
<param name="minInclusive">0.0</param>
<param name="maxInclusive">100.0</param>
</data>
</element>
This specifies a float between 0 and 100.0 inclusive. The other variants are also available, e.g. to exlude the boundary terms using integers,
<element name="rng">
<data type="integer">
<param name="minExclusive">0</param>
<param name="maxExclusive">11</param>
</data>
</element>
This example restricts the value to an integer, between 1 and 10. | |
3. | Restricted precision |
The totalDigits parameter restricts the total number of relevant digits to that specified. For example
<element name="ckDigits">
<data type="decimal">
<param name="totalDigits">6</param>
</data>
</element>
restricts the number of digits to six. This ignores leading and trailing 0's, hence the following would be valid to this restriction. <ckDigits>000123.456000</ckDigits> This is only applicable to data types derived from decimal, hence won't work for floats. See the diagram at W3C for the data type hierarchy. To finish this constraint, it only remains to add that the number of decimal places can be controlled using the fractionDigits parameter, for instance when dealing with monetary values, we might restrict it to 6 digits total, with 2 after the decimal place
<element name="ckDigits">
<data type="decimal">
<param name="totalDigits">6</param>
<param name="fractionDigits">2</param>
</data>
</element>
|