]> ncurses.scripts.mit.edu Git - ncurses.git/blob - man/form_field_validation.3x
54fa2a72a4b4f48c841f02fa53e293ac603b0907
[ncurses.git] / man / form_field_validation.3x
1 .\"***************************************************************************
2 .\" Copyright 2018-2023,2024 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.53 2024/03/16 15:35:01 tom Exp $
31 .TH form_field_validation 3X 2024-03-16 "ncurses @NCURSES_MAJOR@.@NCURSES_MINOR@" "Library calls"
32 .ie \n(.g \{\
33 .ds `` \(lq
34 .ds '' \(rq
35 .\}
36 .el \{\
37 .ie t .ds `` ``
38 .el   .ds `` ""
39 .ie t .ds '' ''
40 .el   .ds '' ""
41 .\}
42 .
43 .de bP
44 .ie n  .IP \(bu 4
45 .el    .IP \(bu 2
46 ..
47 .SH NAME
48 \fBform_field_validation\fP \-
49 data type validation for fields
50 .SH SYNOPSIS
51 .nf
52 \fB#include <form.h>
53 .PP
54 \fBvoid *field_arg(const FIELD *\fIfield\fP);
55 \fBFIELDTYPE *field_type(const FIELD *\fIfield\fP);
56 \fBint set_field_type(FIELD *\fIfield\fP, FIELDTYPE *\fItype\fP, ...);
57 .PP
58 \fI/* predefined field types */\fP
59 \fBFIELDTYPE *TYPE_ALNUM;
60 \fBFIELDTYPE *TYPE_ALPHA;
61 \fBFIELDTYPE *TYPE_ENUM;
62 \fBFIELDTYPE *TYPE_INTEGER;
63 \fBFIELDTYPE *TYPE_NUMERIC;
64 \fBFIELDTYPE *TYPE_REGEXP;
65 \fBFIELDTYPE *TYPE_IPV4;
66 .fi
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\fP 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 .SH PREDEFINED TYPES
87 It is possible to set up new programmer-defined field types.
88 Field types are implemented via the \fBFIELDTYPE\fP data
89 structure, which contains several pointers to functions.
90 .PP
91 See the \fBform_fieldtype\fP(3X) manual page,
92 which describes functions which can be used to construct
93 a field-type dynamically.
94 .PP
95 The predefined types are as follows:
96 .SS TYPE_ALNUM
97 Alphanumeric data.
98 Required parameter:
99 .bP
100 a third \fBint\fP argument, a minimum field width.
101 .SS TYPE_ALPHA
102 Character data.
103 Required parameter:
104 .bP
105 a third \fBint\fP argument, a minimum field width.
106 .SS TYPE_ENUM
107 Accept one of a specified set of strings.
108 Required parameters:
109 .bP
110 a third \fB(char **)\fP argument pointing to a string list;
111 .bP
112 a fourth \fBint\fP flag argument to enable case-sensitivity;
113 .bP
114 a fifth \fBint\fP flag argument specifying whether a partial
115 match must be a unique one.
116 If this flag is off, a prefix matches the first
117 of any set of more than one list elements with that prefix.
118 .PP
119 The library copies the string list,
120 so you may use a list that lives in automatic variables on the stack.
121 .SS TYPE_INTEGER
122 Integer data, parsable to an integer by \fBatoi\fP(3).
123 Required parameters:
124 .bP
125 a third \fBint\fP argument controlling the precision,
126 .bP
127 a fourth \fBlong\fP argument constraining minimum value,
128 .bP
129 a fifth \fBlong\fP constraining maximum value.
130 If the maximum value is less than or equal to the minimum value, the range is
131 simply ignored.
132 .PP
133 On return, the field buffer is formatted according to the
134 \fBprintf\fP format specification \*(``.*ld\*('',
135 where the \*(``*\*('' is replaced by the precision argument.
136 .PP
137 For details of the precision handling see \fBprintf\fP(3).
138 .SS TYPE_NUMERIC
139 Numeric data (may have a decimal-point part).
140 Required parameters:
141 .bP
142 a third \fBint\fP argument controlling the precision,
143 .bP
144 a fourth \fBdouble\fP argument constraining minimum value,
145 .bP
146 and a fifth \fBdouble\fP constraining maximum value.
147 If your system supports locales,
148 the decimal point character must be the one specified by your locale.
149 If the maximum value is less than or equal to the minimum value,
150 the range is simply ignored.
151 .PP
152 On return, the field buffer is formatted according to the
153 \fBprintf\fP format specification \*(``.*f\*('',
154 where the \*(``*\*('' is replaced by the precision argument.
155 .PP
156 For details of the precision handling see \fBprintf\fP(3).
157 .SS TYPE_REGEXP
158 Regular expression data.
159 Required parameter:
160 .bP
161 a third argument, a regular expression \fB(char *)\fP string.
162 The data is valid if the regular expression matches it.
163 .PP
164 Regular expressions
165 are in the format of \fBregcomp\fP and \fBregexec\fP.
166 .PP
167 The regular expression must match the whole field.
168 If you have for example, an eight character wide field,
169 a regular expression "^[0\-9]*$" always
170 means that you have to fill all eight positions with digits.
171 If you want to allow fewer digits,
172 you may use for example "^[0\-9]* *$" which is good for
173 trailing spaces (up to an empty field),
174 or "^ *[0\-9]* *$" which is good for
175 leading and trailing spaces around the digits.
176 .SS TYPE_IPV4
177 An Internet Protocol Version 4 address.
178 Required parameter:
179 .bP
180 none
181 .PP
182 The form library checks whether or not the buffer has the form \fIa.b.c.d\fP,
183 where \fIa\fP, \fIb\fP, \fIc\fP, and \fId\fP are numbers in the range 0 to 255.
184 Trailing blanks in the buffer are ignored.
185 The address itself is not validated.
186 .PP
187 This is an \fI\%ncurses\fP extension;
188 this field type may not be available in other curses implementations.
189 .SH RETURN VALUE
190 The functions \fBfield_type\fP and \fBfield_arg\fP return \fBNULL\fP on error.
191 The function \fBset_field_type\fP returns one of the following:
192 .TP 5
193 .B E_OK
194 The routine succeeded.
195 .TP 5
196 .B E_SYSTEM_ERROR
197 System error occurred (see \fBerrno\fP(3)).
198 .SH PORTABILITY
199 These routines emulate the System V forms library.
200 They were not supported on
201 Version 7 or BSD versions.
202 .SH AUTHORS
203 Juergen Pfeifer.
204 Manual pages and adaptation for new curses by Eric S. Raymond.
205 .SH SEE ALSO
206 \fB\%curses\fP(3X),
207 \fB\%form\fP(3X),
208 \fB\%form_fieldtype\fP(3X),
209 \fB\%form_variables\fP(3X)