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 additional
37 parameters:
38
39 · a third (char **) argument pointing to a string list;
40
41 · a fourth int flag argument to enable case-sensitivity;
42
43 · and a fifth int flag argument specifying whether a partial
44 match must be a unique one. If this flag is off, a prefix
45 matches the first of any set of more than one list elements
46 with that prefix.
47
48 The library copies the string list, so you may use a list that
49 lives in automatic variables on the stack.
50
51 TYPE_INTEGER
52 Integer data, parsable to an integer by atoi(3). Requires addi‐
53 tional parameters:
54
55 · a third int argument controlling the precision,
56
57 · a fourth long argument constraining minimum value,
58
59 · and a fifth long constraining maximum value. If the maximum
60 value is less than or equal to the minimum value, the range is
61 simply ignored. On return, the field buffer is formatted
62 according to the printf format specification “.*ld”, where the
63 “*” is replaced by the precision argument.
64
65 For details of the precision handling see printf(3).
66
67 TYPE_NUMERIC
68 Numeric data (may have a decimal-point part). This requires addi‐
69 tional parameters:
70
71 · a third int argument controlling the precision,
72
73 · a fourth double argument constraining minimum value,
74
75 · and a fifth double constraining maximum value. If your system
76 supports locales, the decimal point character must be the one
77 specified by your locale. If the maximum value is less than
78 or equal to the minimum value, the range is simply ignored.
79
80 On return, the field buffer is formatted according to the
81 printf format specification “.*f”, where the “*” is replaced
82 by the precision argument.
83
84 For details of the precision handling see printf(3).
85
86 TYPE_REGEXP
87 Regular expression data. Requires a regular expression (char *)
88 third argument. The data is valid if the regular expression
89 matches it.
90
91 Regular expressions are in the format of regcomp and regexec.
92
93 The regular expression must match the whole field. If you have
94 for example, an eight character wide field, a regular expression
95 "^[0-9]*$" always means that you have to fill all eight positions
96 with digits. If you want to allow fewer digits, you may use for
97 example "^[0-9]* *$" which is good for trailing spaces (up to an
98 empty field), or "^ *[0-9]* *$" which is good for leading and
99 trailing spaces around the digits.
100
101 TYPE_IPV4
102 An Internet Protocol Version 4 address. This requires no addi‐
103 tional argument. The library checks whether or not the buffer has
104 the form a.b.c.d, where a,b,c and d are numbers between 0 and 255.
105 Trailing blanks in the buffer are ignored. The address itself is
106 not validated.
107
108 This is an ncurses extension; this field type may not be available
109 in other curses implementations.
110
111 It is possible to set up new programmer-defined field types. See the
112 form_fieldtype(3X) manual page.
113
115 The functions field_type and field_arg return NULL on error. The func‐
116 tion set_field_type returns one of the following:
117
118 E_OK The routine succeeded.
119
120 E_SYSTEM_ERROR
121 System error occurred (see errno(3)).
122
124 curses(3X), form(3X), form_variables(3X).
125
127 The header file <form.h> automatically includes the header file
128 <curses.h>.
129
131 These routines emulate the System V forms library. They were not sup‐
132 ported on Version 7 or BSD versions.
133
135 Juergen Pfeifer. Manual pages and adaptation for new curses by Eric S.
136 Raymond.
137
138
139
140 form_field_validation(3X)