1 .\" $OpenBSD: form_field_validation.3,v 1.9 2010/01/12 23:22:07 nicm Exp $
3 .\"***************************************************************************
4 .\" Copyright (c) 1998-2003,2006 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 .\"***************************************************************************
31 .\" $Id: form_field_validation.3,v 1.9 2010/01/12 23:22:07 nicm Exp $
32 .TH form_field_validation 3 ""
34 \fBform_field_validation\fR - data type validation for fields
36 \fB#include <form.h>\fR
38 int set_field_type(FIELD *field, FIELDTYPE *type, ...);
40 FIELDTYPE *field_type(const FIELD *field);
42 void *field_arg(const FIELD *field);
44 FIELDTYPE *TYPE_ALNUM;
46 FIELDTYPE *TYPE_ALPHA;
50 FIELDTYPE *TYPE_INTEGER;
52 FIELDTYPE *TYPE_NUMERIC;
54 FIELDTYPE *TYPE_REGEXP;
59 The function \fBset_field_type\fR declares a data type for a given form field.
60 This is the type checked by validation functions.
61 The predefined types are as follows:
64 Alphanumeric data. Requires a third \fBint\fR argument, a minimum field width.
67 Character data. Requires a third \fBint\fR argument, a minimum field width.
70 Accept one of a specified set of strings. Requires a third \fB(char **)\fR
71 argument pointing to a string list; a fourth \fBint\fR flag argument to enable
72 case-sensitivity; and a fifth \fBint\fR flag argument specifying whether a partial
73 match must be a unique one (if this flag is off, a prefix matches the first
74 of any set of more than one list elements with that prefix). Please notice
75 that the string list is not copied, only a reference to it is stored in the
76 field. So you should avoid using a list that lives in automatic variables
80 Integer data, parsable to an integer by \fBatoi(3)\fR. Requires a third
81 \fBint\fR argument controlling the precision, a fourth \fBlong\fR argument
82 constraining minimum value, and a fifth \fBlong\fR constraining maximum value.
83 If the maximum value is less than or equal to the minimum value, the range is
84 simply ignored. On return the field buffer is formatted according to the
85 \fBprintf\fR format specification ".*ld", where the '*' is replaced by the
87 For details of the precision handling see \fBprintf's\fR man-page.
90 Numeric data (may have a decimal-point part). Requires a third
91 \fBint\fR argument controlling the precision, a fourth \fBdouble\fR
92 argument constraining minimum value, and a fifth \fBdouble\fR constraining
93 maximum value. If your system supports locales, the decimal point character
94 to be used must be the one specified by your locale.
95 If the maximum value is less than or equal to the minimum value, the range is
96 simply ignored. On return the field buffer is formatted according to the
97 \fBprintf\fR format specification ".*f", where the '*' is replaced by the
99 For details of the precision handling see \fBprintf's\fR man-page.
102 Regular expression data. Requires a regular expression \fB(char *)\fR third argument;
103 the data is valid if the regular expression matches it. Regular expressions
104 are in the format of \fBregcomp\fR and \fBregexec\fR. Please notice
105 that the regular expression must match the whole field. If you have for
106 example an eight character wide field, a regular expression "^[0-9]*$" always
107 means that you have to fill all eight positions with digits. If you want to
108 allow fewer digits, you may use for example "^[0-9]* *$" which is good for
109 trailing spaces (up to an empty field), or "^ *[0-9]* *$" which is good for
110 leading and trailing spaces around the digits.
113 An Internet Protocol Version 4 address. This requires no additional argument. It
114 is checked whether or not the buffer has the form a.b.c.d, where a,b,c and d are
115 numbers between 0 and 255. Trailing blanks in the buffer are ignored. The address
116 itself is not validated. Please note that this is an ncurses extension. This
117 field type may not be available in other curses implementations.
119 It is possible to set up new programmer-defined field types. See the
120 \fBform_fieldtype\fR(3) manual page.
122 The functions \fBfield_type\fR and \fBfield_arg\fR return \fBNULL\fR on
123 error. The function \fBset_field_type\fR returns one of the following:
126 The routine succeeded.
129 System error occurred (see \fBerrno\fR).
131 \fBcurses\fR(3), \fBform\fR(3).
133 The header file \fB<form.h>\fR automatically includes the header file
136 These routines emulate the System V forms library. They were not supported on
137 Version 7 or BSD versions.
139 Juergen Pfeifer. Manual pages and adaptation for new curses by Eric
142 .\"# The following sets edit modes for GNU EMACS
143 .\"# Local Variables: