Data Forms (XEP-0004)
The requirements for this document are:
This document defines a new namespace, "http://jabber.org/protocol/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 Data Forms field that possesses additional validation information.
The simplest usage is to provide a more-granular datatype for a <field/> element used in Data Forms. 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:
The preceding example demonstrates a field that is expected to contain a date/time value.
The 'datatype' attribute specifies the datatype. This attribute is OPTIONAL, and defaults to "xs:string". It MUST meet one of the following conditions:
Note that while "x:" allows for ad-hoc definitions, its use is NOT RECOMMENDED.
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:
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.
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.
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.
Using <basic/> validation, the form interpreter MUST follow the validation rules of the datatype (if understood) and the field type.
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:
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.
To indicate that the value should fall within a certain range, the <validate/> element shall contain a <range/> child element:
The 'min' and 'max' attributes of the <range/> element specify the minimum and maximum values allowed, respectively.
The 'max' attribute specifies the maximum allowable value. This attribute is OPTIONAL. The value depends on the datatype in use.
The 'min' attribute specifies the minimum allowable value. This attribute is OPTIONAL. The value depends on the datatype in use.
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.
To indicate that the value should be restricted to a regular expression, the <validate/> element shall contain a <regex/> child element:
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
The <regex/> element MUST contain character data only.
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.
The <list-range/> element SHOULD be included only when the <field/> is of type "list-multi" and SHOULD be ignored otherwise.
The 'max' attribute specifies the maximum allowable number of selected/entered values. This attribute is OPTIONAL. The value MUST be a positive integer.
The 'min' attribute specifies the minimum allowable number of selected/entered values. This attribute is OPTIONAL. The value MUST be a positive integer.
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.
At a minimum, implementations MUST support the following:
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.
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.
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:
This document relies on the internationalization/localization mechanisms provided by XMPP Core
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.
While this document is compatible with the existing "x:data" definition, form providers SHOULD first determine support for it, using either Entity Capabilities (XEP-0115)
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
Validation Method | SHOULD be Allowed | SHOULD NOT be Allowed | Display Suggestions |
---|---|---|---|
basic |
|
|
Display the datatype appropriate to the locale |
open |
|
|
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. |
range |
|
|
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. |
regex |
|
|
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. |
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".
This document introduces no security concerns above and beyond those specified in XEP-0004: Data Forms.
This document requires no interaction with the Internet Assigned Numbers Authority (IANA)
The XMPP Registrar includes 'http://jabber.org/protocol/xdata-validate' in its registry of protocol namespaces.
The XMPP Registrar maintains a registry of datatype prefixes used in the context of Data Forms Validation (see <https://xmpp.org/registrar/xdv-prefixes.html>), where each prefix denotes a group of related datatypes.
In order to submit new values to this registry, the registrant shall define an XML fragment of the following form and either include it in the relevant XMPP Extension Protocol or send it to the email address <registrar@xmpp.org>:
the prefix token (e.g., "xs")
a natural-language description of the datatype family
the document in which datatype family is specified
]]>
The registrant may register more than one prefix at a time, each contained in a separate <datatype-prefix/> element.
As part of this document, the following datatype prefixes shall be registered:
x
An ad-hoc datatype
XEP-0122
xs
A "standard" datatype as defined in XML Schema Part 2
XML Schema Part 2
]]>
The XMPP Registrar maintains a registry of datatypes used in the context of Data Forms Validation (see <https://xmpp.org/registrar/xdv-datatypes.html>), where each datatype name includes the relevant prefix (e.g., "xs:anyURI").
In order to submit new values to this registry, the registrant shall define an XML fragment of the following form and either include it in the relevant XMPP Extension Protocol or send it to the email address <registrar@xmpp.org>:
the full datatype name (e.g., "xs:string")
a natural-language description of the datatype
the validation methods that may apply to the datatype
the minimum value for the datatype (if any)
the maximum value for the datatype (if any)
]]>
The registrant may register more than one datatype at a time, each contained in a separate <datatype/> element.
The following submission contains the built-in datatypes defined in XML Schema Part 2 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.
xs:anyURI
a Uniform Resource Identifier Reference (URI)
basic regex
N/A
N/A
xs:byte
an integer with the specified min/max
basic range
-128
127
xs:date
a calendar date
basic range regex
N/A
N/A
xs:dateTime
a specific instant of time
basic range regex
N/A
N/A
xs:decimal
an arbitrary-precision decimal number
basic range
none
none
xs:double
an IEEE double-precision 64-bit floating point type
basic range
none
none
xs:int
an integer with the specified min/max
basic range
-2147483648
2147483647
xs:integer
a decimal number with no fraction digits
basic range
none
none
xs:language
a language identifier as defined by RFC 1766
basic regex
N/A
N/A
xs:long
an integer with the specified min/max
basic range
-9223372036854775808
9223372036854775807
xs:short
an integer with the specified min/max
basic range
-32768
32767
xs:string
a character strings in XML
basic regex
N/A
N/A
xs:time
an instant of time that recurs every day
basic range regex
N/A
N/A
]]>
]]>