DOC HOME SITE MAP MAN PAGES GNU INFO SEARCH PRINT BOOK
 
Frame definition files

Example of validating a field value with the valid descriptor

Let us add two more descriptors, valid and invalidmsg, to the Zip field definition, as follows:

   .
   .
   .
   name=Zip
   nrow=2
   ncol=30
   columns=5
   valid=`regex -v "$F5" '[0-9]{5}'`
   invalidmsg=Zip code is numeric. Five digits only.
   .
   .
   .

Form.valid: an example of field validation using the valid descriptor

The valid descriptor is defined to execute regex to validate the field. If a pattern is matched by regex, regex will write the corresponding template to stdout. The regex utility will also return the value TRUE which, for FMLI built-in utilities, is analogous to a UNIX system command that exits with status 0. If no pattern is matched, regex will not write to stdout and will return FALSE. For FMLI built-in utilities, FALSE is equivalent to a UNIX system command that exits with a non-zero exit status. For example, the field validation shown in ``Form.valid: an example of field validation using the valid descriptor'' (that is, the valid descriptor definition) uses the -v option to regex to specify that the argument that follows (rather than stdin) should be used as input. Note that this regex statement contains a single pattern without a template. In regex, a template is optional if only one pattern exists. The last pattern in a series of pattern/template pairs is also optional.

This use of regex will return TRUE if the current value of field 5 consists entirely of integers and will return FALSE otherwise. Since no template exists, regex will not write to stdout. If the field is not numeric and not all five digits are entered, the following message defined by the invalidmsg descriptor is displayed:

   Zip code is numeric. Five digits only.

Next topic: Text frames
Previous topic: Form.6choices: screen output after user selects an item from the choices menu

© 2004 The SCO Group, Inc. All rights reserved.
UnixWare 7 Release 7.1.4 - 27 April 2004