• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1<!--
2  ****************************************************************************
3  * Copyright 2018-2023,2024 Thomas E. Dickey                                *
4  * Copyright 1998-2010,2017 Free Software Foundation, Inc.                  *
5  *                                                                          *
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:                 *
13  *                                                                          *
14  * The above copyright notice and this permission notice shall be included  *
15  * in all copies or substantial portions of the Software.                   *
16  *                                                                          *
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.                               *
24  *                                                                          *
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       *
28  * authorization.                                                           *
29  ****************************************************************************
30  * @Id: form_field_validation.3x,v 1.53 2024/03/16 15:35:01 tom Exp @
31-->
32<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN">
33<HTML>
34<HEAD>
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 2024-03-16 ncurses 6.5 Library calls</TITLE>
38<link rel="author" href="mailto:bug-ncurses@gnu.org">
39
40</HEAD>
41<BODY>
42<H1 class="no-header">form_field_validation 3x 2024-03-16 ncurses 6.5 Library calls</H1>
43<PRE>
44<STRONG><A HREF="form_field_validation.3x.html">form_field_validation(3x)</A></STRONG>        Library calls       <STRONG><A HREF="form_field_validation.3x.html">form_field_validation(3x)</A></STRONG>
45
46
47
48
49</PRE><H2><a name="h2-NAME">NAME</a></H2><PRE>
50       <STRONG>form_field_validation</STRONG> - data type validation for fields
51
52
53</PRE><H2><a name="h2-SYNOPSIS">SYNOPSIS</a></H2><PRE>
54       <STRONG>#include</STRONG> <STRONG>&lt;form.h&gt;</STRONG>
55
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>
59
60       <EM>/*</EM> <EM>predefined</EM> <EM>field</EM> <EM>types</EM> <EM>*/</EM>
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>
68
69
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.
73
74
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.
79
80
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>.
84
85
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>.
91
92       Several field types are predefined by the form library.
93
94
95</PRE><H2><a name="h2-PREDEFINED-TYPES">PREDEFINED TYPES</a></H2><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.
99
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.
102
103       The predefined types are as follows:
104
105
106</PRE><H3><a name="h3-TYPE_ALNUM">TYPE_ALNUM</a></H3><PRE>
107       Alphanumeric data.  Required parameter:
108
109       <STRONG>o</STRONG>   a third <STRONG>int</STRONG> argument, a minimum field width.
110
111
112</PRE><H3><a name="h3-TYPE_ALPHA">TYPE_ALPHA</a></H3><PRE>
113       Character data.  Required parameter:
114
115       <STRONG>o</STRONG>   a third <STRONG>int</STRONG> argument, a minimum field width.
116
117
118</PRE><H3><a name="h3-TYPE_ENUM">TYPE_ENUM</a></H3><PRE>
119       Accept one of a specified set of strings.  Required parameters:
120
121       <STRONG>o</STRONG>   a third <STRONG>(char</STRONG> <STRONG>**)</STRONG> argument pointing to a string list;
122
123       <STRONG>o</STRONG>   a fourth <STRONG>int</STRONG> flag argument to enable case-sensitivity;
124
125       <STRONG>o</STRONG>   a  fifth  <STRONG>int</STRONG> flag argument specifying whether a partial match must
126           be a unique one.  If this flag is off, a prefix matches  the  first
127           of any set of more than one list elements with that prefix.
128
129       The library copies the string list, so you may use a list that lives in
130       automatic variables on the stack.
131
132
133</PRE><H3><a name="h3-TYPE_INTEGER">TYPE_INTEGER</a></H3><PRE>
134       Integer data, parsable to an integer by <STRONG>atoi(3)</STRONG>.  Required parameters:
135
136       <STRONG>o</STRONG>   a third <STRONG>int</STRONG> argument controlling the precision,
137
138       <STRONG>o</STRONG>   a fourth <STRONG>long</STRONG> argument constraining minimum value,
139
140       <STRONG>o</STRONG>   a fifth <STRONG>long</STRONG> constraining maximum value.  If the maximum  value  is
141           less  than  or  equal  to  the  minimum  value, the range is simply
142           ignored.
143
144       On return, the field buffer is formatted according to the <STRONG>printf</STRONG> format
145       specification  ".*ld",  where  the  "*"  is  replaced  by the precision
146       argument.
147
148       For details of the precision handling see <STRONG>printf(3)</STRONG>.
149
150
151</PRE><H3><a name="h3-TYPE_NUMERIC">TYPE_NUMERIC</a></H3><PRE>
152       Numeric data (may have a decimal-point part).  Required parameters:
153
154       <STRONG>o</STRONG>   a third <STRONG>int</STRONG> argument controlling the precision,
155
156       <STRONG>o</STRONG>   a fourth <STRONG>double</STRONG> argument constraining minimum value,
157
158       <STRONG>o</STRONG>   and a fifth <STRONG>double</STRONG> constraining  maximum  value.   If  your  system
159           supports  locales,  the  decimal  point  character  must be the one
160           specified by your locale.  If the maximum value  is  less  than  or
161           equal to the minimum value, the range is simply ignored.
162
163       On return, the field buffer is formatted according to the <STRONG>printf</STRONG> format
164       specification ".*f",  where  the  "*"  is  replaced  by  the  precision
165       argument.
166
167       For details of the precision handling see <STRONG>printf(3)</STRONG>.
168
169
170</PRE><H3><a name="h3-TYPE_REGEXP">TYPE_REGEXP</a></H3><PRE>
171       Regular expression data.  Required parameter:
172
173       <STRONG>o</STRONG>   a  third  argument, a regular expression <STRONG>(char</STRONG> <STRONG>*)</STRONG> string.  The data
174           is valid if the regular expression matches it.
175
176       Regular expressions are in the format of <STRONG>regcomp</STRONG> and <STRONG>regexec</STRONG>.
177
178       The regular expression must match the whole field.   If  you  have  for
179       example, an eight character wide field, a regular expression "^[0-9]*$"
180       always means that you have to fill all eight positions with digits.  If
181       you  want  to  allow fewer digits, you may use for example "^[0-9]* *$"
182       which is good for trailing spaces (up to an empty field), or "^ *[0-9]*
183       *$" which is good for leading and trailing spaces around the digits.
184
185
186</PRE><H3><a name="h3-TYPE_IPV4">TYPE_IPV4</a></H3><PRE>
187       An Internet Protocol Version 4 address.  Required parameter:
188
189       <STRONG>o</STRONG>   none
190
191       The form library checks whether or not the buffer has the form <EM>a.b.c.d</EM>,
192       where <EM>a</EM>, <EM>b</EM>, <EM>c</EM>, and <EM>d</EM> are numbers in  the  range  0  to  255.   Trailing
193       blanks in the buffer are ignored.  The address itself is not validated.
194
195       This  is  an <EM>ncurses</EM> extension; this field type may not be available in
196       other curses implementations.
197
198
199</PRE><H2><a name="h2-RETURN-VALUE">RETURN VALUE</a></H2><PRE>
200       The functions <STRONG>field_type</STRONG> and  <STRONG>field_arg</STRONG>  return  <STRONG>NULL</STRONG>  on  error.   The
201       function <STRONG>set_field_type</STRONG> returns one of the following:
202
203       <STRONG>E_OK</STRONG> The routine succeeded.
204
205       <STRONG>E_SYSTEM_ERROR</STRONG>
206            System error occurred (see <STRONG>errno(3)</STRONG>).
207
208
209</PRE><H2><a name="h2-PORTABILITY">PORTABILITY</a></H2><PRE>
210       These  routines  emulate  the  System  V  forms library.  They were not
211       supported on Version 7 or BSD versions.
212
213
214</PRE><H2><a name="h2-AUTHORS">AUTHORS</a></H2><PRE>
215       Juergen Pfeifer.  Manual pages and adaptation for new curses by Eric S.
216       Raymond.
217
218
219</PRE><H2><a name="h2-SEE-ALSO">SEE ALSO</a></H2><PRE>
220       <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>
221
222
223
224ncurses 6.5                       2024-03-16         <STRONG><A HREF="form_field_validation.3x.html">form_field_validation(3x)</A></STRONG>
225</PRE>
226<div class="nav">
227<ul>
228<li><a href="#h2-NAME">NAME</a></li>
229<li><a href="#h2-SYNOPSIS">SYNOPSIS</a></li>
230<li><a href="#h2-DESCRIPTION">DESCRIPTION</a>
231<ul>
232<li><a href="#h3-field_arg">field_arg</a></li>
233<li><a href="#h3-field_type">field_type</a></li>
234<li><a href="#h3-set_field_type">set_field_type</a></li>
235</ul>
236</li>
237<li><a href="#h2-PREDEFINED-TYPES">PREDEFINED TYPES</a>
238<ul>
239<li><a href="#h3-TYPE_ALNUM">TYPE_ALNUM</a></li>
240<li><a href="#h3-TYPE_ALPHA">TYPE_ALPHA</a></li>
241<li><a href="#h3-TYPE_ENUM">TYPE_ENUM</a></li>
242<li><a href="#h3-TYPE_INTEGER">TYPE_INTEGER</a></li>
243<li><a href="#h3-TYPE_NUMERIC">TYPE_NUMERIC</a></li>
244<li><a href="#h3-TYPE_REGEXP">TYPE_REGEXP</a></li>
245<li><a href="#h3-TYPE_IPV4">TYPE_IPV4</a></li>
246</ul>
247</li>
248<li><a href="#h2-RETURN-VALUE">RETURN VALUE</a></li>
249<li><a href="#h2-PORTABILITY">PORTABILITY</a></li>
250<li><a href="#h2-AUTHORS">AUTHORS</a></li>
251<li><a href="#h2-SEE-ALSO">SEE ALSO</a></li>
252</ul>
253</div>
254</BODY>
255</HTML>
256