2 ****************************************************************************
3 * Copyright 2018-2021,2022 Thomas E. Dickey *
4 * Copyright 1998-2010,2017 Free Software Foundation, Inc. *
6 * Permission is hereby granted, free of charge, to any person obtaining a *
7 * copy of this software and associated documentation files (the *
8 * "Software"), to deal in the Software without restriction, including *
9 * without limitation the rights to use, copy, modify, merge, publish, *
10 * distribute, distribute with modifications, sublicense, and/or sell *
11 * copies of the Software, and to permit persons to whom the Software is *
12 * furnished to do so, subject to the following conditions: *
14 * The above copyright notice and this permission notice shall be included *
15 * in all copies or substantial portions of the Software. *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
20 * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
21 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
22 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
23 * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
25 * Except as contained in this notice, the name(s) of the above copyright *
26 * holders shall not be used in advertising or otherwise to promote the *
27 * sale, use or other dealings in this Software without prior written *
29 ****************************************************************************
30 * @Id: form_field_validation.3x,v 1.36 2022/02/12 20:03:40 tom Exp @
32 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN">
35 <meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
36 <meta name="generator" content="Manpage converted by man2html - see https://invisible-island.net/scripts/readme.html#others_scripts">
37 <TITLE>form_field_validation 3x</TITLE>
38 <link rel="author" href="mailto:bug-ncurses@gnu.org">
42 <H1 class="no-header">form_field_validation 3x</H1>
44 <STRONG><A HREF="form_field_validation.3x.html">form_field_validation(3x)</A></STRONG> <STRONG><A HREF="form_field_validation.3x.html">form_field_validation(3x)</A></STRONG>
49 </PRE><H2><a name="h2-NAME">NAME</a></H2><PRE>
50 <STRONG>form_field_validation</STRONG> - data type validation for fields
53 </PRE><H2><a name="h2-SYNOPSIS">SYNOPSIS</a></H2><PRE>
54 <STRONG>#include</STRONG> <STRONG><form.h></STRONG>
56 <STRONG>void</STRONG> <STRONG>*field_arg(const</STRONG> <STRONG>FIELD</STRONG> <STRONG>*</STRONG><EM>field</EM><STRONG>);</STRONG>
57 <STRONG>FIELDTYPE</STRONG> <STRONG>*field_type(const</STRONG> <STRONG>FIELD</STRONG> <STRONG>*</STRONG><EM>field</EM><STRONG>);</STRONG>
58 <STRONG>int</STRONG> <STRONG>set_field_type(FIELD</STRONG> <STRONG>*</STRONG><EM>field</EM><STRONG>,</STRONG> <STRONG>FIELDTYPE</STRONG> <STRONG>*</STRONG><EM>type</EM><STRONG>,</STRONG> <STRONG>...);</STRONG>
60 /* predefined field types */
61 <STRONG>FIELDTYPE</STRONG> <STRONG>*TYPE_ALNUM;</STRONG>
62 <STRONG>FIELDTYPE</STRONG> <STRONG>*TYPE_ALPHA;</STRONG>
63 <STRONG>FIELDTYPE</STRONG> <STRONG>*TYPE_ENUM;</STRONG>
64 <STRONG>FIELDTYPE</STRONG> <STRONG>*TYPE_INTEGER;</STRONG>
65 <STRONG>FIELDTYPE</STRONG> <STRONG>*TYPE_NUMERIC;</STRONG>
66 <STRONG>FIELDTYPE</STRONG> <STRONG>*TYPE_REGEXP;</STRONG>
67 <STRONG>FIELDTYPE</STRONG> <STRONG>*TYPE_IPV4;</STRONG>
70 </PRE><H2><a name="h2-DESCRIPTION">DESCRIPTION</a></H2><PRE>
71 By default, no validation is done on form fields. You can associate a
72 form with with a <EM>field</EM> <EM>type</EM>, making the form library validate input.
75 </PRE><H3><a name="h3-field_arg">field_arg</a></H3><PRE>
76 Returns a pointer to the field's argument block. The <EM>argument</EM> <EM>block</EM> is
77 an opaque structure containing a copy of the arguments provided in a
78 <STRONG>set_field_type</STRONG> call.
81 </PRE><H3><a name="h3-field_type">field_type</a></H3><PRE>
82 Returns a pointer to the <EM>field</EM> <EM>type</EM> associated with the form field,
83 i.e., by calling <STRONG>set_field_type</STRONG>.
86 </PRE><H3><a name="h3-set_field_type">set_field_type</a></H3><PRE>
87 The function <STRONG>set_field_type</STRONG> associates a field type with a given form
88 field. This is the type checked by validation functions. Most field
89 types are configurable, via arguments which the caller provides when
90 calling <STRONG>set_field_type</STRONG>.
92 Several field types are predefined by the form library.
95 </PRE><H3><a name="h3-Predefined-types">Predefined types</a></H3><PRE>
96 It is possible to set up new programmer-defined field types. Field
97 types are implemented via the <STRONG>FIELDTYPE</STRONG> data structure, which contains
98 several pointers to functions.
100 See the <STRONG><A HREF="form_fieldtype.3x.html">form_fieldtype(3x)</A></STRONG> manual page, which describes functions which
101 can be used to construct a field-type dynamically.
103 The predefined types are as follows:
106 Alphanumeric data. Required parameter:
108 <STRONG>o</STRONG> a third <STRONG>int</STRONG> argument, a minimum field width.
111 Character data. Required parameter:
113 <STRONG>o</STRONG> a third <STRONG>int</STRONG> argument, a minimum field width.
116 Accept one of a specified set of strings. Required parameters:
118 <STRONG>o</STRONG> a third <STRONG>(char</STRONG> <STRONG>**)</STRONG> argument pointing to a string list;
120 <STRONG>o</STRONG> a fourth <STRONG>int</STRONG> flag argument to enable case-sensitivity;
122 <STRONG>o</STRONG> a fifth <STRONG>int</STRONG> flag argument specifying whether a partial match
123 must be a unique one. If this flag is off, a prefix matches
124 the first of any set of more than one list elements with that
127 The library copies the string list, so you may use a list that
128 lives in automatic variables on the stack.
131 Integer data, parsable to an integer by <STRONG>atoi(3)</STRONG>. Required
134 <STRONG>o</STRONG> a third <STRONG>int</STRONG> argument controlling the precision,
136 <STRONG>o</STRONG> a fourth <STRONG>long</STRONG> argument constraining minimum value,
138 <STRONG>o</STRONG> a fifth <STRONG>long</STRONG> constraining maximum value. If the maximum value
139 is less than or equal to the minimum value, the range is
142 On return, the field buffer is formatted according to the <STRONG>printf</STRONG>
143 format specification ".*ld", where the "*" is replaced by the
146 For details of the precision handling see <STRONG>printf(3)</STRONG>.
149 Numeric data (may have a decimal-point part). Required
152 <STRONG>o</STRONG> a third <STRONG>int</STRONG> argument controlling the precision,
154 <STRONG>o</STRONG> a fourth <STRONG>double</STRONG> argument constraining minimum value,
156 <STRONG>o</STRONG> and a fifth <STRONG>double</STRONG> constraining maximum value. If your system
157 supports locales, the decimal point character must be the one
158 specified by your locale. If the maximum value is less than
159 or equal to the minimum value, the range is simply ignored.
161 On return, the field buffer is formatted according to the <STRONG>printf</STRONG>
162 format specification ".*f", where the "*" is replaced by the
165 For details of the precision handling see <STRONG>printf(3)</STRONG>.
168 Regular expression data. Required parameter:
170 <STRONG>o</STRONG> a third argument, a regular expression <STRONG>(char</STRONG> <STRONG>*)</STRONG> string. The
171 data is valid if the regular expression matches it.
173 Regular expressions are in the format of <STRONG>regcomp</STRONG> and <STRONG>regexec</STRONG>.
175 The regular expression must match the whole field. If you have
176 for example, an eight character wide field, a regular expression
177 "^[0-9]*$" always means that you have to fill all eight positions
178 with digits. If you want to allow fewer digits, you may use for
179 example "^[0-9]* *$" which is good for trailing spaces (up to an
180 empty field), or "^ *[0-9]* *$" which is good for leading and
181 trailing spaces around the digits.
184 An Internet Protocol Version 4 address. Required parameter:
186 <STRONG>o</STRONG> none
188 The form library checks whether or not the buffer has the form
189 <EM>a.b.c.d</EM>, where <EM>a</EM>, <EM>b</EM>, <EM>c</EM>, and <EM>d</EM> are numbers in the range 0 to 255.
190 Trailing blanks in the buffer are ignored. The address itself is
193 This is an ncurses extension; this field type may not be available
194 in other curses implementations.
197 </PRE><H2><a name="h2-RETURN-VALUE">RETURN VALUE</a></H2><PRE>
198 The functions <STRONG>field_type</STRONG> and <STRONG>field_arg</STRONG> return <STRONG>NULL</STRONG> on error. The
199 function <STRONG>set_field_type</STRONG> returns one of the following:
201 <STRONG>E_OK</STRONG> The routine succeeded.
203 <STRONG>E_SYSTEM_ERROR</STRONG>
204 System error occurred (see <STRONG>errno(3)</STRONG>).
207 </PRE><H2><a name="h2-SEE-ALSO">SEE ALSO</a></H2><PRE>
208 <STRONG><A HREF="ncurses.3x.html">curses(3x)</A></STRONG>, <STRONG><A HREF="form.3x.html">form(3x)</A></STRONG>, <STRONG><A HREF="form_fieldtype.3x.html">form_fieldtype(3x)</A></STRONG>, <STRONG><A HREF="form_variables.3x.html">form_variables(3x)</A></STRONG>.
211 </PRE><H2><a name="h2-NOTES">NOTES</a></H2><PRE>
212 The header file <STRONG><form.h></STRONG> automatically includes the header file
213 <STRONG><curses.h></STRONG>.
216 </PRE><H2><a name="h2-PORTABILITY">PORTABILITY</a></H2><PRE>
217 These routines emulate the System V forms library. They were not
218 supported on Version 7 or BSD versions.
221 </PRE><H2><a name="h2-AUTHORS">AUTHORS</a></H2><PRE>
222 Juergen Pfeifer. Manual pages and adaptation for new curses by Eric S.
227 <STRONG><A HREF="form_field_validation.3x.html">form_field_validation(3x)</A></STRONG>
231 <li><a href="#h2-NAME">NAME</a></li>
232 <li><a href="#h2-SYNOPSIS">SYNOPSIS</a></li>
233 <li><a href="#h2-DESCRIPTION">DESCRIPTION</a>
235 <li><a href="#h3-field_arg">field_arg</a></li>
236 <li><a href="#h3-field_type">field_type</a></li>
237 <li><a href="#h3-set_field_type">set_field_type</a></li>
238 <li><a href="#h3-Predefined-types">Predefined types</a></li>
241 <li><a href="#h2-RETURN-VALUE">RETURN VALUE</a></li>
242 <li><a href="#h2-SEE-ALSO">SEE ALSO</a></li>
243 <li><a href="#h2-NOTES">NOTES</a></li>
244 <li><a href="#h2-PORTABILITY">PORTABILITY</a></li>
245 <li><a href="#h2-AUTHORS">AUTHORS</a></li>