1 .\"***************************************************************************
2 .\" Copyright 2018-2022,2023 Thomas E. Dickey *
3 .\" Copyright 1998-2010,2017 Free Software Foundation, Inc. *
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: *
13 .\" The above copyright notice and this permission notice shall be included *
14 .\" in all copies or substantial portions of the Software. *
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. *
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 *
28 .\"***************************************************************************
30 .\" $Id: form_field_validation.3x,v 1.44 2023/09/16 23:37:03 tom Exp $
31 .TH form_field_validation 3X 2023-09-16 "ncurses 6.4" "Library calls"
41 \fBform_field_validation\fP \-
42 data type validation for fields
44 \fB#include <form.h>\fP
46 \fBvoid *field_arg(const FIELD *\fIfield\fB);\fR
48 \fBFIELDTYPE *field_type(const FIELD *\fIfield\fB);\fR
50 \fBint set_field_type(FIELD *\fIfield\fB, FIELDTYPE *\fItype\fB, ...);\fR
52 /* predefined field types */
54 \fBFIELDTYPE *TYPE_ALNUM;\fP
56 \fBFIELDTYPE *TYPE_ALPHA;\fP
58 \fBFIELDTYPE *TYPE_ENUM;\fP
60 \fBFIELDTYPE *TYPE_INTEGER;\fP
62 \fBFIELDTYPE *TYPE_NUMERIC;\fP
64 \fBFIELDTYPE *TYPE_REGEXP;\fP
66 \fBFIELDTYPE *TYPE_IPV4;\fP
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.
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.
76 Returns a pointer to the \fIfield type\fP associated with the form field,
77 i.e., by calling \fBset_field_type\fP.
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.
85 Several field types are predefined by the form library.
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.
91 See the \fBform_fieldtype\fP(3X) manual page,
92 which describes functions which can be used to construct
93 a field-type dynamically.
95 The predefined types are as follows:
100 a third \fBint\fP argument, a minimum field width.
105 a third \fBint\fP argument, a minimum field width.
107 Accept one of a specified set of strings.
110 a third \fB(char **)\fP argument pointing to a string list;
112 a fourth \fBint\fP flag argument to enable case-sensitivity;
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.
119 The library copies the string list,
120 so you may use a list that lives in automatic variables on the stack.
122 Integer data, parsable to an integer by \fBatoi\fP(3).
125 a third \fBint\fP argument controlling the precision,
127 a fourth \fBlong\fP argument constraining minimum value,
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
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.
137 For details of the precision handling see \fBprintf\fP(3).
139 Numeric data (may have a decimal-point part).
142 a third \fBint\fP argument controlling the precision,
144 a fourth \fBdouble\fP argument constraining minimum value,
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.
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.
156 For details of the precision handling see \fBprintf\fP(3).
158 Regular expression data.
161 a third argument, a regular expression \fB(char *)\fP string.
162 The data is valid if the regular expression matches it.
165 are in the format of \fBregcomp\fP and \fBregexec\fP.
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.
177 An Internet Protocol Version 4 address.
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.
187 This is an ncurses extension;
188 this field type may not be available in other curses implementations.
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:
194 The routine succeeded.
197 System error occurred (see \fBerrno\fP(3)).
201 \fBform_fieldtype\fP(3X),
202 \fBform_variables\fP(3X).
204 The header file \fB<form.h>\fP automatically includes the header file
207 These routines emulate the System V forms library.
208 They were not supported on
209 Version 7 or BSD versions.
212 Manual pages and adaptation for new curses by Eric S. Raymond.