Regex pattern and replace functions

From W3C XForms Group Wiki (Public)
Jump to: navigation, search

It is possible to provide a regex pattern constraint for a data node using the type MIP and a schema datatype.

However, it is not possible to vary the regex used based on a condition. For example, very old US social security numbers use a different format from newer ones, and if you split the input across form controls, then the digit pattern for a second field is dependent on whether two or three digits were entered into a first field.

For this reason as well as authoring convenience, it would be very helpful if a function like the XPath 2.0 matches() function were available in the XForms function library, even for processors using an XPath 1.0 expression engine.

Similarly, XPath 2.0 also has a replace() function that takes an input, a regex, and a pattern that describes how capture groups in the regex should be used to produce a return string. For example, a call along the lines of replace(ssn, '(\d{3})(\d{2})(\d{4})', '$1-$2-$3') would return the ssn with dashes added. This function would be important to have particularly in the value attribute of setvalue actions, but one can easily envision scenarios where it would be useful even in a calculate formula. User:Jboyer