]> ncurses.scripts.mit.edu Git - ncurses.git/blob - man/form_field_validation.3x
ncurses 6.2 - patch 20210703
[ncurses.git] / man / form_field_validation.3x
1 .\"***************************************************************************
2 .\" Copyright 2018-2019,2020 Thomas E. Dickey                                *
3 .\" Copyright 1998-2010,2017 Free Software Foundation, Inc.                  *
4 .\"                                                                          *
5 .\" Permission is hereby granted, free of charge, to any person obtaining a  *
6 .\" copy of this software and associated documentation files (the            *
7 .\" "Software"), to deal in the Software without restriction, including      *
8 .\" without limitation the rights to use, copy, modify, merge, publish,      *
9 .\" distribute, distribute with modifications, sublicense, and/or sell       *
10 .\" copies of the Software, and to permit persons to whom the Software is    *
11 .\" furnished to do so, subject to the following conditions:                 *
12 .\"                                                                          *
13 .\" The above copyright notice and this permission notice shall be included  *
14 .\" in all copies or substantial portions of the Software.                   *
15 .\"                                                                          *
16 .\" THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS  *
17 .\" OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF               *
18 .\" MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.   *
19 .\" IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,   *
20 .\" DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR    *
21 .\" OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR    *
22 .\" THE USE OR OTHER DEALINGS IN THE SOFTWARE.                               *
23 .\"                                                                          *
24 .\" Except as contained in this notice, the name(s) of the above copyright   *
25 .\" holders shall not be used in advertising or otherwise to promote the     *
26 .\" sale, use or other dealings in this Software without prior written       *
27 .\" authorization.                                                           *
28 .\"***************************************************************************
29 .\"
30 .\" $Id: form_field_validation.3x,v 1.33 2020/12/12 19:57:55 tom Exp $
31 .TH form_field_validation 3X ""
32 .ie \n(.g .ds `` \(lq
33 .el       .ds `` ``
34 .ie \n(.g .ds '' \(rq
35 .el       .ds '' ''
36 .de bP
37 .ie n  .IP \(bu 4
38 .el    .IP \(bu 2
39 ..
40 .SH NAME
41 \fBform_field_validation\fR \- data type validation for fields
42 .SH SYNOPSIS
43 \fB#include <form.h>\fR
44 .sp
45 \fBvoid *field_arg(const FIELD *\fP\fIfield\fP\fB);\fP
46 .br
47 \fBFIELDTYPE *field_type(const FIELD *\fP\fIfield\fP\fB);\fP
48 .br
49 \fBint set_field_type(FIELD *\fP\fIfield\fP\fB, FIELDTYPE *\fP\fItype\fP\fB, ...);\fP
50 .sp
51 /* predefined field types */
52 .br
53 \fBFIELDTYPE *TYPE_ALNUM;\fP
54 .br
55 \fBFIELDTYPE *TYPE_ALPHA;\fP
56 .br
57 \fBFIELDTYPE *TYPE_ENUM;\fP
58 .br
59 \fBFIELDTYPE *TYPE_INTEGER;\fP
60 .br
61 \fBFIELDTYPE *TYPE_NUMERIC;\fP
62 .br
63 \fBFIELDTYPE *TYPE_REGEXP;\fP
64 .br
65 \fBFIELDTYPE *TYPE_IPV4;\fP
66 .br
67 .SH DESCRIPTION
68 By default, no validation is done on form fields.
69 You can associate a form with with a \fIfield type\fP,
70 making the form library validate input.
71 .SS field_arg
72 Returns a pointer to the field's argument block.
73 The \fIargument block\fP is an opaque structure containing
74 a copy of the arguments provided in a \fBset_field_type\fP call.
75 .SS field_type
76 Returns a pointer to the \fIfield type\fP associated with the form field,
77 i.e., by calling \fBset_field_type\fP.
78 .SS set_field_type
79 The function \fBset_field_type\fR associates
80 a field type with a given form field.
81 This is the type checked by validation functions.
82 Most field types are configurable,
83 via arguments which the caller provides when calling \fBset_field_type\fP.
84 .PP
85 Several field types are predefined by the form library.
86 .SS Predefined types
87 .PP
88 It is possible to set up new programmer-defined field types.
89 Field types are implemented via the \fBFIELDTYPE\fP data
90 structure, which contains several pointers to functions.
91 .PP
92 See the \fBform_fieldtype\fR(3X) manual page,
93 which describes functions which can be used to construct
94 a field-type dynamically.
95 .PP
96 The predefined types are as follows:
97 .TP 5
98 TYPE_ALNUM
99 Alphanumeric data.
100 Required parameter:
101 .RS
102 .bP
103 a third \fBint\fR argument, a minimum field width.
104 .RE
105 .TP 5
106 TYPE_ALPHA
107 Character data.
108 Required parameter:
109 .RS
110 .bP
111 a third \fBint\fR argument, a minimum field width.
112 .RE
113 .TP 5
114 TYPE_ENUM
115 Accept one of a specified set of strings.
116 Required parameters:
117 .RS
118 .bP
119 a third \fB(char **)\fR argument pointing to a string list;
120 .bP
121 a fourth \fBint\fR flag argument to enable case-sensitivity;
122 .bP
123 a fifth \fBint\fR flag argument specifying whether a partial
124 match must be a unique one.
125 If this flag is off, a prefix matches the first
126 of any set of more than one list elements with that prefix.
127 .RE
128 .IP
129 The library copies the string list,
130 so you may use a list that lives in automatic variables on the stack.
131 .TP 5
132 TYPE_INTEGER
133 Integer data, parsable to an integer by \fBatoi\fP(3).
134 Required parameters:
135 .RS
136 .bP
137 a third \fBint\fR argument controlling the precision,
138 .bP
139 a fourth \fBlong\fR argument constraining minimum value,
140 .bP
141 a fifth \fBlong\fR constraining maximum value.
142 If the maximum value is less than or equal to the minimum value, the range is
143 simply ignored.
144 .RE
145 .IP
146 On return, the field buffer is formatted according to the
147 \fBprintf\fR format specification \*(``.*ld\*('',
148 where the \*(``*\*('' is replaced by the precision argument.
149 .IP
150 For details of the precision handling see \fBprintf\fR(3).
151 .TP 5
152 TYPE_NUMERIC
153 Numeric data (may have a decimal-point part).
154 Required parameters:
155 .RS
156 .bP
157 a third \fBint\fR argument controlling the precision,
158 .bP
159 a fourth \fBdouble\fR argument constraining minimum value,
160 .bP
161 and a fifth \fBdouble\fR constraining maximum value.
162 If your system supports locales,
163 the decimal point character must be the one specified by your locale.
164 If the maximum value is less than or equal to the minimum value,
165 the range is simply ignored.
166 .RE
167 .IP
168 On return, the field buffer is formatted according to the
169 \fBprintf\fR format specification \*(``.*f\*('',
170 where the \*(``*\*('' is replaced by the precision argument.
171 .IP
172 For details of the precision handling see \fBprintf\fR(3).
173 .TP 5
174 TYPE_REGEXP
175 Regular expression data.
176 Required parameter:
177 .RS
178 .bP
179 a third argument, a regular expression \fB(char *)\fR string.
180 The data is valid if the regular expression matches it.
181 .RE
182 .IP
183 Regular expressions
184 are in the format of \fBregcomp\fR and \fBregexec\fR.
185 .IP
186 The regular expression must match the whole field.
187 If you have for example, an eight character wide field,
188 a regular expression "^[0\-9]*$" always
189 means that you have to fill all eight positions with digits.
190 If you want to allow fewer digits,
191 you may use for example "^[0\-9]* *$" which is good for
192 trailing spaces (up to an empty field),
193 or "^ *[0\-9]* *$" which is good for
194 leading and trailing spaces around the digits.
195 .TP 5
196 TYPE_IPV4
197 An Internet Protocol Version 4 address.
198 Required parameter:
199 .RS
200 .bP
201 none
202 .RE
203 .IP
204 The form library checks whether or not the buffer has the form \fIa.b.c.d\fP,
205 where \fIa\fP, \fIb\fP, \fIc\fP, and \fId\fP are numbers in the range 0 to 255.
206 Trailing blanks in the buffer are ignored.
207 The address itself is not validated.
208 .IP
209 This is an ncurses extension;
210 this field type may not be available in other curses implementations.
211 .SH RETURN VALUE
212 The functions \fBfield_type\fR and \fBfield_arg\fR return \fBNULL\fR on error.
213 The function \fBset_field_type\fR returns one of the following:
214 .TP 5
215 .B E_OK
216 The routine succeeded.
217 .TP 5
218 .B E_SYSTEM_ERROR
219 System error occurred (see \fBerrno\fR(3)).
220 .SH SEE ALSO
221 \fBcurses\fR(3X),
222 \fBform\fR(3X),
223 \fBform_fieldtype\fR(3X),
224 \fBform_variables\fR(3X).
225 .SH NOTES
226 The header file \fB<form.h>\fR automatically includes the header file
227 \fB<curses.h>\fR.
228 .SH PORTABILITY
229 These routines emulate the System V forms library.
230 They were not supported on
231 Version 7 or BSD versions.
232 .SH AUTHORS
233 Juergen Pfeifer.
234 Manual pages and adaptation for new curses by Eric S. Raymond.