<abstract>This specification defines a backwards-compatible extension to the XMPP Data Forms protocol that enables applications to specify additional validation guidelines related to a form, such as validation of standard XML datatypes, application-specific datatypes, value ranges, and regular expressions.</abstract>
<remark>Replaced method attribute with dedicated elements; removed Formal Definition section in favor of defining requirements within the use-cases and XML schema; included display considerations; added reference to XEP-0115.</remark>
<remark>Replaced <text-list/> with specific interpretations for other validation methods; Further clarified use of validation methods (other than "basic") with "list-single", "list-multi", and "text-multi"; Fixed errors in some examples; initial datatype registrations.</remark>
</revision>
<revision>
<version>0.5</version>
<date>2004-05-27</date>
<initials>lw</initials>
<remark>Added <text-list/> ("text as a list") support; Clarified <list-range/> expanded discussion on datatype registries.</remark>
</revision>
<revision>
<version>0.4</version>
<date>2004-01-29</date>
<initials>lw</initials>
<remark>Removed "std" datatypes; Added references to XML Schema built-in datatypes.</remark>
<p>&xep0004; ("x:data") provides a simple and interoperable way to request and present information for both applications and humans. However, the simple nature of "x:data" requires the form interpreter at times to guess as to exactly what type of information is being requested or provided. This document builds upon "x:data" to provide this additional validation.</p>
<p>This document defines a new namespace, "http://jabber.org/protocols/xdata-validate". The root element for this namespace is <validate/>, and MUST be contained within a <field/> element (qualified by the 'jabber:x:data' namespace) for each <cite>Data Forms</cite> field that possesses additional validation information.</p>
<p>The simplest usage is to provide a more-granular datatype for a <field/> element used in <cite>Data Forms</cite>. To provide this datatype information, a <validate/> element is included whose 'datatype' attribute specifies the data type of any <value/> contained within the <field/> element:</p>
<examplecaption='Field with extended datatype'><![CDATA[
<p>The preceding example demonstrates a field that is expected to contain a date/time value.</p>
<p>The 'datatype' attribute specifies the datatype. This attribute is OPTIONAL, and defaults to "xs:string". It MUST meet one of the following conditions:</p>
<ul>
<li>Start with "xs:", and be one of the "built-in" datatypes defined in &w3xmlschema2;</li>
<li>Start with a prefix registered with the ®ISTRAR;</li>
<li>Start with "x:", and specify a user-defined datatype<note>While "x:" allows for ad-hoc definitions, its use is NOT RECOMMENDED.</note></li>
<p>In addition to datatypes, the validation method can also be provided. The method is specified via a child element. The validation methods defined in this document are:</p>
<li><basic/> for validation only against the datatype itself</li>
<li><open/> for open-ended validation against the datatype</li>
<li><range/> for validation against a given min/max and the datatype</li>
<li><regex/> for validation against a given regular expression and the datatype</li>
</ul>
<p>If no validation method is specified, form processors MUST assume <basic/> validation. The <validate/> element SHOULD include one of the above validation method elements, and MUST NOT include more than one.</p>
<p>Any validation method applied to a field of type "list-multi", "list-single", or "text-multi" (other than <basic/>) MUST imply the same behavior as <open/>, with the additional constraints defined by that method.</p>
<p>Building upon the earlier example, to indicate that the value(s) should simply match the field type and datatype constraints, the <validate/> element shall contain a <basic/> child element.</p>
<p>For "list-single" or "list-multi", to indicate that the user may enter a custom value (matching the datatype constraints) or choose from the predefined values, the <validate/> element shall contain an <open/> child element:</p>
<p>The <open/> validation method applies to "text-multi" differently; it hints that each value for a "text-multi" field shall be validated separately. This effectively turns "text-multi" fields into an open-ended "list-multi", with no options and all values automatically selected.</p>
<p>The <open/> element MUST be empty (i.e., not contain any character data or child elements) and MUST NOT possess any attributes.</p>
<p>The 'min' and 'max' attributes of the <range/> element specify the minimum and maximum values allowed, respectively.</p>
<p>The 'max' attribute specifies the maximum allowable value. This attribute is OPTIONAL. The value depends on the datatype in use.</p>
<p>The 'min' attribute specifies the minimum allowable value. This attribute is OPTIONAL. The value depends on the datatype in use.</p>
<p>The <range/> element SHOULD possess either a 'min' or 'max' attribute, and MAY possess both. If neither attribute is included, the processor MUST assume that there are no range constraints.</p>
<p>The <range/> element MUST be empty (i.e., not contain any character data or child elements).</p>
<p>To indicate that the value should be restricted to a regular expression, the <validate/> element shall contain a <regex/> child element:</p>
<p>The XML character data of this element is the pattern to apply. The syntax of this content MUST be that defined for POSIX extended regular expressions<note>The "best" definition of this syntax can be found in the <linkurl='http://www.gsp.com/cgi-bin/man.cgi?section=7&topic=re_format'>re_format(7) man page</link></note>, including support for Unicode<note>Guidelines for adapting regular expressions to support Unicode is defined at <linkurl='http://www.unicode.org/reports/tr18/'>http://www.unicode.org/reports/tr18/</link></note>.</p>
<p>The <regex/> element MUST contain character data only (i.e., not contain any child elements) and MUST NOT possess any attributes.</p>
<p>For "list-multi", validation can indicate (via the <list-range/> element) that a minimum and maximum number of options should be selected and/or entered. This selection range MAY be combined with the other methods to provide more flexibility.</p>
<examplecaption='Selection Range validation'><![CDATA[
<p>The <list-range/> element SHOULD be included only when the <field/> is of type "list-multi" and SHOULD be ignored otherwise.</p>
<p>The 'max' attribute specifies the maximum allowable number of selected/entered values. This attribute is OPTIONAL. The value MUST be a positive integer.</p>
<p>The 'min' attribute specifies the minimum allowable number of selected/entered values. This attribute is OPTIONAL. The value MUST be a positive integer.</p>
<p>The <list-range/> element SHOULD possess either a 'min' or 'max' attribute, and MAY possess both. If neither attribute is included, the processor MUST assume that there are no selection constraints.</p>
<section2topic='Required to Support'anchor='impl-req'>
<p>At a minimum, implementations MUST support the following:</p>
<ul>
<li>Datatype validation</li>
<li>The <basic/> validation method</li>
</ul>
<p>If an implementation does not understand the specified datatype, it MUST validate according to the default "xs:string" datatype. If an implementation does not understand the specified method, it MUST validate according to the <basic/> method.</p>
<p>While all elements associated with this document MUST be qualified by the 'http://jabber.org/protocol/xdata-validate' namespace, explicitly declaring the default namespace for each instance can be overly verbose. However, Jabber/XMPP implementations have historically been very lax regarding namespacing, thus requiring some careful use of prefixes.</p>
<p>The use of namespace prefixes is RECOMMENDED for large forms, to reduce the data size. To maintain the highest level of compatibility, implementations sending the form using prefixes SHOULD use the namespace prefix "xdv", and SHOULD declare the namespace prefix mapping in the ancestor <x xmlns='jabber:x:data'/> element:</p>
<examplecaption='Example of recommended namespace prefixing'><![CDATA[
<p>This document relies on the internationalization/localization mechanisms provided by &xmppcore;. As much as possible, all datatype formats MUST be locale-independent.</p>
<p>Form processors MUST NOT assume that a form with validation has actually been validated when submitted. There is no realistic expectation that form interpreters honor validation.</p>
<p>While this document is compatible with the existing "x:data" definition, form providers SHOULD first determine support for it, using either &xep0115; if presence-aware or &xep0030;. This is especially important for limited-connection and/or limited-capabilities devices, such as cell phones.</p>
<p>Although primarily intended for validating form submission, validation MAY have an impact on display, and MAY be applied to data forms that are not submitted (e.g. 'result' type forms). The following table outlines which field types a particular validation method is or is not appropriate for, and how a display SHOULD interpret the validation methods if considered<note>If a particular field type is not listed, the display MAY include validation support, but is not expected to do so.</note>:</p>
<tablecaption='Validation Methods and Field Types'>
<tr>
<th>Validation Method</th>
<th>SHOULD be Allowed</th>
<th>SHOULD NOT be Allowed</th>
<th>Display Suggestions</th>
</tr>
<tr>
<td>basic</td>
<td><ul>
<li>fixed</li>
<li>list-multi</li>
<li>list-single</li>
<li>text-multi</li>
<li>text-single</li>
</ul></td>
<td><ul>
<li>hidden</li>
<li>jid-multi</li>
<li>jid-single</li>
</ul></td>
<td>Display the datatype appropriate to the locale</td>
</tr>
<tr>
<td>open</td>
<td><ul>
<li>jid-multi</li>
<li>jid-single</li>
<li>list-multi</li>
<li>list-single</li>
<li>text-multi</li>
<li>text-single</li>
</ul></td>
<td><ul>
<li>hidden</li>
</ul></td>
<td>Display the datatype appropriate to the locale. For "text-multi" treat each value as a discrete entry (e.g. a user-entered list). For "list-multi" or "list-single", allow user to add/remove entries to select.</td>
</tr>
<tr>
<td>range</td>
<td><ul>
<li>text-single</li>
</ul></td>
<td><ul>
<li>hidden</li>
<li>jid-multi</li>
<li>list-multi</li>
<li>text-multi</li>
</ul></td>
<td>Display the datatype appropriate to the locale. For "text-single", allow user to increment/decrement through possible values. For "text-multi" treat each value as a discrete entry (e.g. a user-entered list). For "list-multi" or "list-single", allow user to add/remove entries to select.</td>
</tr>
<tr>
<td>regex</td>
<td><ul>
<li>text-single</li>
</ul></td>
<td><ul>
<li>hidden</li>
<li>jid-multi</li>
<li>list-multi</li>
<li>text-multi</li>
</ul></td>
<td>Display the datatype appropriate to the locale. If possible, display a valid example. For "text-multi" treat each value as a discrete entry (e.g. a user-entered list). For "list-multi" or "list-single", allow user to add/remove entries to select.</td>
<p>The <range/> validation method MUST be used only with datatypes that have finite quantities. Within the standard datatype set, it MUST NOT be used with "xs:string".</p>
<p>The XMPP Registrar maintains a registry of datatype prefixes used in the context of Data Forms Validation (see &XDVPREFIXES;), where each prefix denotes a group of related datatypes.</p>
<p>The XMPP Registrar maintains a registry of datatypes used in the context of Data Forms Validation (see &XDVTYPES;), where each datatype name includes the relevant prefix (e.g., "xs:anyURI").</p>
<p>The following submission contains the built-in datatypes defined in <cite>XML Schema Part 2</cite> that are deemed mostly like to be useful in the context of the Data Forms protocol; additional datatypes defined therein, as well as other datatypes not defined in XML Schema Part 2, may be registered via separate submissions in the future.</p>