4.4 An Email Datatype for XForms

One of the great disappointments in the XForms specification is the lack of a defined datatype for email the one datatype common to nearly every Web form. Even if the specification doesn't define an email datatype, form designers still can. Getting all the details right is a little tricky, though. Since regular expressions aren't a programming language, there's no way to define a common recurring segment, and the regular expression tends to get a little repetitive. Taken one step at a time, however, it makes perfect sense. The datatype definition conforming to RFC 2822 is:

<xs:simpleType name="email">   <xs:restriction base="xs:string">     <xs:pattern value="[A-Za-z0-9!#-'\*\+\-/=\?\^_`\{-~]+         (\.[A-Za-z0-9!#-'\*\+\-/=\?\^_`\{-~]+)*@[A-Za-z0-9!#-         '\*\+\-/=\?\^_`\{-~]+(\.[A-Za-z0-9!#-'\*\+\-/=\?\^_`\         {-~]+)*"/>   </xs:restriction> </xs:simpleType>

The main achievement in this lengthy statement is the definition of what the email address specification calls atext, which is defined alpha characters, digits, or one of the following characters:

"!" "#" "$" "%" "&" "'" "*" "+" "-" "/" "=" "?" "^" "_" "`" "{" "|" "}" "~"

In regular expression syntax, the definition for a single character of atext looks like this:

[A-Za-z0-9!#-'\*\+\-/=\?\^_`\{-~]

Note that the character ranges in this expression prevent it from being even bulkier, and that a number of the characters used need to be escaped. If you compare this with the entire regular expression given earlier, you will see that this definition repeats four times overall. If regular expressions had a way to define a commonly-recurring string, the regular expression might look like this (with spaces added for readability):

atext+ (\. atext+)* @ atext+ (\. atext+)*

But alas, the actual regular expression needs to repeat the full definition of atext four times, yielding the full definition of the email datatype.

4.4.1 Using the Email Datatype

This datatype definition is available online, so any XForms definition that includes the XML Schema at http://dubinko.info/writing/xforms/email.xsd will be able to support email datatypes in forms.

<xforms:model schema="http://dubinko.info/writing/xforms/datatypes.xsd"> ...


XForms Essentials
Xforms Essentials
ISBN: 0596003692
EAN: 2147483647
Year: 2005
Pages: 117
Authors: Micah Dubinko

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net