XForms-Transitional Testbed - regular expressions

This is part of a series of cross-platform experiments in incremental extensions to HTML4 forms that provide a stepping stone towards the much richer capabilities in XForms. This particular experiment introduces a pattern attribute that tests input for a match to a regular expression.

Please view the XForms-Transitional script for more details on how this works.

Patterns

Here is the markup for the above form:

<form name="form1" onsubmit="false">
<fieldset>
<legend>Patterns</legend>
<label for="f1"
title="must resemble 1234-1234-1234">Card number</label>
<input id="f1" name="cardnum" value="1234-1234-1234"
pattern="^\d\d\d\d-\d\d\d\d-\d\d\d\d$"/>
</fieldset>

Comments

The pattern attribute can be used on all fields whether their values are calculated or manually entered. If the field doesn't match the pattern, the script library adds "invalid" to the classes set on the input element and any associated label elements. This can be used from CSS to style invalid fields.The title attribute may be used to provide a tool tip, and will be copied between the input and label elements as appropriate. Further guidance can be given by including a link within the label. The implementation avoids the labels, valid and pattern field properties as these are already used by Opera for the WebForms 2.0 proposal.

It might be worth testing validity when the field still has the focus and the user hasn't typed anything for a while. A balance needs to be drawn between providing useful feedback and the risk of causing irritation.

The user might find it helpful if the field is initialized to a hint that disappears when the field gets the focus and reappears when the focus is removed and the user has yet to provide a value. How does the script identify such hints? One possibility would be a hint attribute, but that has internationalization problems like the value attribute. The script should avoid showing the hint if the field's value isn't null -- this allows cached values to show.

Dave Raggett <dsr@w3.org>