1form_field_validation(3X)                            form_field_validation(3X)
2
3
4

NAME

6       form_field_validation - data type validation for fields
7

SYNOPSIS

9       #include <form.h>
10
11       void *field_arg(const FIELD *field);
12       FIELDTYPE *field_type(const FIELD *field);
13       int set_field_type(FIELD *field, FIELDTYPE *type, ...);
14
15       /* predefined field types */
16       FIELDTYPE *TYPE_ALNUM;
17       FIELDTYPE *TYPE_ALPHA;
18       FIELDTYPE *TYPE_ENUM;
19       FIELDTYPE *TYPE_INTEGER;
20       FIELDTYPE *TYPE_NUMERIC;
21       FIELDTYPE *TYPE_REGEXP;
22       FIELDTYPE *TYPE_IPV4;
23

DESCRIPTION

25       By  default, no validation is done on form fields.  You can associate a
26       form with with a field type, making the form library validate input.
27
28   field_arg
29       Returns a pointer to the field's argument block.  The argument block is
30       an  opaque  structure  containing a copy of the arguments provided in a
31       set_field_type call.
32
33   field_type
34       Returns a pointer to the field type associated  with  the  form  field,
35       i.e., by calling set_field_type.
36
37   set_field_type
38       The  function  set_field_type associates a field type with a given form
39       field.  This is the type checked by validation functions.   Most  field
40       types  are  configurable,  via arguments which the caller provides when
41       calling set_field_type.
42
43       Several field types are predefined by the form library.
44
45   Predefined types
46       It is possible to set up new  programmer-defined  field  types.   Field
47       types  are implemented via the FIELDTYPE data structure, which contains
48       several pointers to functions.
49
50       See the form_fieldtype(3X) manual page, which describes functions which
51       can be used to construct a field-type dynamically.
52
53       The predefined types are as follows:
54
55       TYPE_ALNUM
56            Alphanumeric data.  Required parameter:
57
58            •   a third int argument, a minimum field width.
59
60       TYPE_ALPHA
61            Character data.  Required parameter:
62
63            •   a third int argument, a minimum field width.
64
65       TYPE_ENUM
66            Accept one of a specified set of strings.  Required parameters:
67
68            •   a third (char **) argument pointing to a string list;
69
70            •   a fourth int flag argument to enable case-sensitivity;
71
72            •   a  fifth  int flag argument specifying whether a partial match
73                must be a unique one.  If this flag is off, a  prefix  matches
74                the  first of any set of more than one list elements with that
75                prefix.
76
77            The library copies the string list, so you may  use  a  list  that
78            lives in automatic variables on the stack.
79
80       TYPE_INTEGER
81            Integer data, parsable to an integer by atoi(3).  Required parame‐
82            ters:
83
84            •   a third int argument controlling the precision,
85
86            •   a fourth long argument constraining minimum value,
87
88            •   a fifth long constraining maximum value.  If the maximum value
89                is  less than or equal to the minimum value, the range is sim‐
90                ply ignored.
91
92            On return, the field buffer is formatted according to  the  printf
93            format specification “.*ld”, where the “*” is replaced by the pre‐
94            cision argument.
95
96            For details of the precision handling see printf(3).
97
98       TYPE_NUMERIC
99            Numeric data (may have a decimal-point  part).   Required  parame‐
100            ters:
101
102            •   a third int argument controlling the precision,
103
104            •   a fourth double argument constraining minimum value,
105
106            •   and a fifth double constraining maximum value.  If your system
107                supports locales, the decimal point character must be the  one
108                specified  by  your locale.  If the maximum value is less than
109                or equal to the minimum value, the range is simply ignored.
110
111            On return, the field buffer is formatted according to  the  printf
112            format  specification “.*f”, where the “*” is replaced by the pre‐
113            cision argument.
114
115            For details of the precision handling see printf(3).
116
117       TYPE_REGEXP
118            Regular expression data.  Required parameter:
119
120            •   a third argument, a regular expression (char *)  string.   The
121                data is valid if the regular expression matches it.
122
123            Regular expressions are in the format of regcomp and regexec.
124
125            The  regular  expression  must match the whole field.  If you have
126            for example, an eight character wide field, a  regular  expression
127            "^[0-9]*$"  always means that you have to fill all eight positions
128            with digits.  If you want to allow fewer digits, you may  use  for
129            example  "^[0-9]*  *$" which is good for trailing spaces (up to an
130            empty field), or "^ *[0-9]* *$" which  is  good  for  leading  and
131            trailing spaces around the digits.
132
133       TYPE_IPV4
134            An Internet Protocol Version 4 address.  Required parameter:
135
136            •   none
137
138            The  form  library  checks  whether or not the buffer has the form
139            a.b.c.d, where a, b, c, and d are numbers in the range 0  to  255.
140            Trailing  blanks in the buffer are ignored.  The address itself is
141            not validated.
142
143            This is an ncurses extension; this field type may not be available
144            in other curses implementations.
145

RETURN VALUE

147       The functions field_type and field_arg return NULL on error.  The func‐
148       tion set_field_type returns one of the following:
149
150       E_OK The routine succeeded.
151
152       E_SYSTEM_ERROR
153            System error occurred (see errno(3)).
154

SEE ALSO

156       curses(3X), form(3X), form_fieldtype(3X), form_variables(3X).
157

NOTES

159       The  header  file  <form.h>  automatically  includes  the  header  file
160       <curses.h>.
161

PORTABILITY

163       These  routines emulate the System V forms library.  They were not sup‐
164       ported on Version 7 or BSD versions.
165

AUTHORS

167       Juergen Pfeifer.  Manual pages and adaptation for new curses by Eric S.
168       Raymond.
169
170
171
172                                                     form_field_validation(3X)
Impressum