]> ncurses.scripts.mit.edu Git - ncurses.git/blob - man/form_field_validation.3x
ncurses 6.1 - patch 20181208
[ncurses.git] / man / form_field_validation.3x
1 .\"***************************************************************************
2 .\" Copyright (c) 1998-2017,2018 Free Software Foundation, Inc.              *
3 .\"                                                                          *
4 .\" Permission is hereby granted, free of charge, to any person obtaining a  *
5 .\" copy of this software and associated documentation files (the            *
6 .\" "Software"), to deal in the Software without restriction, including      *
7 .\" without limitation the rights to use, copy, modify, merge, publish,      *
8 .\" distribute, distribute with modifications, sublicense, and/or sell       *
9 .\" copies of the Software, and to permit persons to whom the Software is    *
10 .\" furnished to do so, subject to the following conditions:                 *
11 .\"                                                                          *
12 .\" The above copyright notice and this permission notice shall be included  *
13 .\" in all copies or substantial portions of the Software.                   *
14 .\"                                                                          *
15 .\" THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS  *
16 .\" OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF               *
17 .\" MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.   *
18 .\" IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,   *
19 .\" DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR    *
20 .\" OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR    *
21 .\" THE USE OR OTHER DEALINGS IN THE SOFTWARE.                               *
22 .\"                                                                          *
23 .\" Except as contained in this notice, the name(s) of the above copyright   *
24 .\" holders shall not be used in advertising or otherwise to promote the     *
25 .\" sale, use or other dealings in this Software without prior written       *
26 .\" authorization.                                                           *
27 .\"***************************************************************************
28 .\"
29 .\" $Id: form_field_validation.3x,v 1.23 2018/07/28 21:18:11 tom Exp $
30 .TH form_field_validation 3X ""
31 .de bP
32 .ie n  .IP \(bu 4
33 .el    .IP \(bu 2
34 ..
35 .SH NAME
36 \fBform_field_validation\fR \- data type validation for fields
37 .SH SYNOPSIS
38 \fB#include <form.h>\fR
39 .br
40 int set_field_type(FIELD *field, FIELDTYPE *type, ...);
41 .br
42 FIELDTYPE *field_type(const FIELD *field);
43 .br
44 void *field_arg(const FIELD *field);
45 .sp
46 FIELDTYPE *TYPE_ALNUM;
47 .br
48 FIELDTYPE *TYPE_ALPHA;
49 .br
50 FIELDTYPE *TYPE_ENUM;
51 .br
52 FIELDTYPE *TYPE_INTEGER;
53 .br
54 FIELDTYPE *TYPE_NUMERIC;
55 .br
56 FIELDTYPE *TYPE_REGEXP;
57 .br
58 FIELDTYPE *TYPE_IPV4;
59 .br
60 .SH DESCRIPTION
61 The function \fBset_field_type\fR declares a data type for a given form field.
62 This is the type checked by validation functions.
63 The predefined types are as follows:
64 .TP 5
65 TYPE_ALNUM
66 Alphanumeric data.
67 Requires a third \fBint\fR argument, a minimum field width.
68 .TP 5
69 TYPE_ALPHA
70 Character data.
71 Requires a third \fBint\fR argument, a minimum field width.
72 .TP 5
73 TYPE_ENUM
74 Accept one of a specified set of strings.
75 Requires additional parameters:
76 .RS
77 .bP
78 a third \fB(char **)\fR argument pointing to a string list;
79 .bP
80 a fourth \fBint\fR flag argument to enable case-sensitivity;
81 .bP
82 and a fifth \fBint\fR flag argument specifying whether a partial
83 match must be a unique one.
84 If this flag is off, a prefix matches the first
85 of any set of more than one list elements with that prefix.
86 .IP
87 The library copies the string list,
88 so you may use a list that lives in automatic variables on the stack.
89 .RE
90 .TP 5
91 TYPE_INTEGER
92 Integer data, parsable to an integer by \fBatoi\fP(3).
93 Requires additional parameters:
94 .RS
95 .bP
96 a third \fBint\fR argument controlling the precision,
97 .bP
98 a fourth \fBlong\fR argument constraining minimum value,
99 .bP
100 and a fifth \fBlong\fR constraining maximum value.
101 If the maximum value is less than or equal to the minimum value, the range is
102 simply ignored.
103 On return, the field buffer is formatted according to the
104 \fBprintf\fR format specification ".*ld", where the '*' is replaced by the
105 precision argument.
106 .IP
107 For details of the precision handling see \fBprintf's\fR man-page.
108 .RE
109 .TP 5
110 TYPE_NUMERIC
111 Numeric data (may have a decimal-point part).
112 This requires additional parameters:
113 .RS
114 .bP
115 a third \fBint\fR argument controlling the precision,
116 .bP
117 a fourth \fBdouble\fR argument constraining minimum value,
118 .bP
119 and a fifth \fBdouble\fR constraining maximum value.
120 If your system supports locales,
121 the decimal point character must be the one specified by your locale.
122 If the maximum value is less than or equal to the minimum value,
123 the range is simply ignored.
124 .IP
125 On return, the field buffer is formatted according to the
126 \fBprintf\fR format specification ".*f", where the '*' is replaced by the
127 precision argument.
128 .IP
129 For details of the precision handling see \fBprintf's\fR man-page.
130 .RE
131 .TP 5
132 TYPE_REGEXP
133 Regular expression data.
134 Requires a regular expression \fB(char *)\fR third argument.
135 The data is valid if the regular expression matches it.
136 .IP
137 Regular expressions
138 are in the format of \fBregcomp\fR and \fBregexec\fR.
139 .IP
140 The regular expression must match the whole field.
141 If you have for example, an eight character wide field,
142 a regular expression "^[0\-9]*$" always
143 means that you have to fill all eight positions with digits.
144 If you want to allow fewer digits,
145 you may use for example "^[0\-9]* *$" which is good for
146 trailing spaces (up to an empty field),
147 or "^ *[0\-9]* *$" which is good for
148 leading and trailing spaces around the digits.
149 .TP 5
150 TYPE_IPV4
151 An Internet Protocol Version 4 address.
152 This requires no additional argument.
153 The library checks whether or not the buffer has the form a.b.c.d,
154 where a,b,c and d are numbers between 0 and 255.
155 Trailing blanks in the buffer are ignored.
156 The address itself is not validated.
157 .IP
158 This is an ncurses extension;
159 this field type may not be available in other curses implementations.
160 .PP
161 It is possible to set up new programmer-defined field types.
162 See the \fBform_fieldtype\fR(3X) manual page.
163 .SH RETURN VALUE
164 The functions \fBfield_type\fR and \fBfield_arg\fR return \fBNULL\fR on error.
165 The function \fBset_field_type\fR returns one of the following:
166 .TP 5
167 .B E_OK
168 The routine succeeded.
169 .TP 5
170 .B E_SYSTEM_ERROR
171 System error occurred (see \fBerrno\fR).
172 .SH SEE ALSO
173 \fBcurses\fR(3X),
174 \fBform\fR(3X),
175 \fBform_variables\fR(3X).
176 .SH NOTES
177 The header file \fB<form.h>\fR automatically includes the header file
178 \fB<curses.h>\fR.
179 .SH PORTABILITY
180 These routines emulate the System V forms library.
181 They were not supported on
182 Version 7 or BSD versions.
183 .SH AUTHORS
184 Juergen Pfeifer.
185 Manual pages and adaptation for new curses by Eric S. Raymond.