1form_field_validation(3X) form_field_validation(3X)
2
3
4
6 form_field_validation - data type validation for fields
7
9 #include <form.h>
10 int set_field_type(FIELD *field, FIELDTYPE *type, ...);
11 FIELDTYPE *field_type(const FIELD *field);
12 void *field_arg(const FIELD *field);
13
14 FIELDTYPE *TYPE_ALNUM;
15 FIELDTYPE *TYPE_ALPHA;
16 FIELDTYPE *TYPE_ENUM;
17 FIELDTYPE *TYPE_INTEGER;
18 FIELDTYPE *TYPE_NUMERIC;
19 FIELDTYPE *TYPE_REGEXP;
20 FIELDTYPE *TYPE_IPV4;
21
23 The function set_field_type declares a data type for a given form
24 field. This is the type checked by validation functions. The prede‐
25 fined types are as follows:
26
27 TYPE_ALNUM
28 Alphanumeric data. Requires a third int argument, a minimum field
29 width.
30
31 TYPE_ALPHA
32 Character data. Requires a third int argument, a minimum field
33 width.
34
35 TYPE_ENUM
36 Accept one of a specified set of strings. Requires a third (char
37 **) argument pointing to a string list; a fourth int flag argument
38 to enable case-sensitivity; and a fifth int flag argument specify‐
39 ing whether a partial match must be a unique one (if this flag is
40 off, a prefix matches the first of any set of more than one list
41 elements with that prefix). Please notice that the string list is
42 not copied, only a reference to it is stored in the field. So you
43 should avoid using a list that lives in automatic variables on the
44 stack.
45
46 TYPE_INTEGER
47 Integer data, parsable to an integer by atoi(3). Requires a third
48 int argument controlling the precision, a fourth long argument
49 constraining minimum value, and a fifth long constraining maximum
50 value. If the maximum value is less than or equal to the minimum
51 value, the range is simply ignored. On return the field buffer is
52 formatted according to the printf format specification ".*ld",
53 where the '*' is replaced by the precision argument. For details
54 of the precision handling see printf's man-page.
55
56 TYPE_NUMERIC
57 Numeric data (may have a decimal-point part). Requires a third int
58 argument controlling the precision, a fourth double argument con‐
59 straining minimum value, and a fifth double constraining maximum
60 value. If your system supports locales, the decimal point charac‐
61 ter to be used must be the one specified by your locale. If the
62 maximum value is less than or equal to the minimum value, the
63 range is simply ignored. On return the field buffer is formatted
64 according to the printf format specification ".*f", where the '*'
65 is replaced by the precision argument. For details of the preci‐
66 sion handling see printf's man-page.
67
68 TYPE_REGEXP
69 Regular expression data. Requires a regular expression (char *)
70 third argument; the data is valid if the regular expression
71 matches it. Regular expressions are in the format of regcomp and
72 regexec. Please notice that the regular expression must match the
73 whole field. If you have for example an eight character wide
74 field, a regular expression "^[0-9]*$" always means that you have
75 to fill all eight positions with digits. If you want to allow
76 fewer digits, you may use for example "^[0-9]* *$" which is good
77 for trailing spaces (up to an empty field), or "^ *[0-9]* *$"
78 which is good for leading and trailing spaces around the digits.
79
80 TYPE_IPV4
81 An Internet Protocol Version 4 address. This requires no addi‐
82 tional argument. It is checked whether or not the buffer has the
83 form a.b.c.d, where a,b,c and d are numbers between 0 and 255.
84 Trailing blanks in the buffer are ignored. The address itself is
85 not validated. Please note that this is an ncurses extension. This
86 field type may not be available in other curses implementations.
87
88 It is possible to set up new programmer-defined field types. See the
89 form_fieldtype(3X) manual page.
90
92 The functions field_type and field_arg return NULL on error. The func‐
93 tion set_field_type returns one of the following:
94
95 E_OK The routine succeeded.
96
97 E_SYSTEM_ERROR
98 System error occurred (see errno).
99
101 curses(3X), form(3X).
102
104 The header file <form.h> automatically includes the header file
105 <curses.h>.
106
108 These routines emulate the System V forms library. They were not sup‐
109 ported on Version 7 or BSD versions.
110
112 Juergen Pfeifer. Manual pages and adaptation for new curses by Eric S.
113 Raymond.
114
115
116
117 form_field_validation(3X)