6.9.8 Match and Result Functions

The match and result functions implement regular expressions, as found in the UNIX editor ed(1). The match function matches a string with a regular expression, and the result function returns the substrings matched by the match function.

The next example uses the match function to verify that a phone number entered in the phone field is in the correct format (ddd) ddd-dddd, where d represents a digit.

The area code, prefix and number are extracted into the area, prefix, and number fields respectively with the result function.

Form Name ex8

Data File

Beginning form no Unique records no

Repeating form no Append form no

Freeze form no Additional form no

Required form no for one record

Next form name ex8

gifs/00000001.gif

Field name phone Field length 13

Entry Allowed yes Input required no

In Data File no Invisible no

Edit/Match if ! match (phone,"([0-9]\{3\})[0-9]\{3\}-[0-9]\{4\}")

"Invalid phone number"

endif

Edit Data Type string

Field name area Field length 3

Entry Allowed no Input required no

In Data File no Invisible no

Calculation if match (phone,"(\([0-9]\{3\}\))[0-9]\{3\}-[0-9]\{4\}")

result (1)

endif

Edit Data Type string

Field name prefix Field length 3

Entry Allowed no Input required no

In Data File no Invisible no

Calculation if match (phone,"([0-9]\{3\})\([0-9]\{3\}\)-[0-9]\{4\}")

result (1)

endif

Edit Data Type string

Field name number Field length 4

Entry Allowed no Input required no

In Data File no Invisible no

Calculation if match (phone,"([0-9]\{3\})[0-9]\{3\}-\([0-9]\{4\}\)")

result (1)

endif

Edit Data Type string

Figure 8