]> ncurses.scripts.mit.edu Git - ncurses.git/blob - man/form_field_validation.3x
ncurses 6.1 - patch 20190907
[ncurses.git] / man / form_field_validation.3x
1 .\"***************************************************************************
2 .\" Copyright (c) 1998-2018,2019 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.24 2019/01/20 20:31:42 tom Exp $
30 .TH form_field_validation 3X ""
31 .ie \n(.g .ds `` \(lq
32 .el       .ds `` ``
33 .ie \n(.g .ds '' \(rq
34 .el       .ds '' ''
35 .de bP
36 .ie n  .IP \(bu 4
37 .el    .IP \(bu 2
38 ..
39 .SH NAME
40 \fBform_field_validation\fR \- data type validation for fields
41 .SH SYNOPSIS
42 \fB#include <form.h>\fR
43 .br
44 int set_field_type(FIELD *field, FIELDTYPE *type, ...);
45 .br
46 FIELDTYPE *field_type(const FIELD *field);
47 .br
48 void *field_arg(const FIELD *field);
49 .sp
50 FIELDTYPE *TYPE_ALNUM;
51 .br
52 FIELDTYPE *TYPE_ALPHA;
53 .br
54 FIELDTYPE *TYPE_ENUM;
55 .br
56 FIELDTYPE *TYPE_INTEGER;
57 .br
58 FIELDTYPE *TYPE_NUMERIC;
59 .br
60 FIELDTYPE *TYPE_REGEXP;
61 .br
62 FIELDTYPE *TYPE_IPV4;
63 .br
64 .SH DESCRIPTION
65 The function \fBset_field_type\fR declares a data type for a given form field.
66 This is the type checked by validation functions.
67 The predefined types are as follows:
68 .TP 5
69 TYPE_ALNUM
70 Alphanumeric data.
71 Requires a third \fBint\fR argument, a minimum field width.
72 .TP 5
73 TYPE_ALPHA
74 Character data.
75 Requires a third \fBint\fR argument, a minimum field width.
76 .TP 5
77 TYPE_ENUM
78 Accept one of a specified set of strings.
79 Requires additional parameters:
80 .RS
81 .bP
82 a third \fB(char **)\fR argument pointing to a string list;
83 .bP
84 a fourth \fBint\fR flag argument to enable case-sensitivity;
85 .bP
86 and a fifth \fBint\fR flag argument specifying whether a partial
87 match must be a unique one.
88 If this flag is off, a prefix matches the first
89 of any set of more than one list elements with that prefix.
90 .IP
91 The library copies the string list,
92 so you may use a list that lives in automatic variables on the stack.
93 .RE
94 .TP 5
95 TYPE_INTEGER
96 Integer data, parsable to an integer by \fBatoi\fP(3).
97 Requires additional parameters:
98 .RS
99 .bP
100 a third \fBint\fR argument controlling the precision,
101 .bP
102 a fourth \fBlong\fR argument constraining minimum value,
103 .bP
104 and a fifth \fBlong\fR constraining maximum value.
105 If the maximum value is less than or equal to the minimum value, the range is
106 simply ignored.
107 On return, the field buffer is formatted according to the
108 \fBprintf\fR format specification \*(``.*ld\*('',
109 where the \*(``*\*('' is replaced by the precision argument.
110 .IP
111 For details of the precision handling see \fBprintf\fR(3).
112 .RE
113 .TP 5
114 TYPE_NUMERIC
115 Numeric data (may have a decimal-point part).
116 This requires additional parameters:
117 .RS
118 .bP
119 a third \fBint\fR argument controlling the precision,
120 .bP
121 a fourth \fBdouble\fR argument constraining minimum value,
122 .bP
123 and a fifth \fBdouble\fR constraining maximum value.
124 If your system supports locales,
125 the decimal point character must be the one specified by your locale.
126 If the maximum value is less than or equal to the minimum value,
127 the range is simply ignored.
128 .IP
129 On return, the field buffer is formatted according to the
130 \fBprintf\fR format specification \*(``.*f\*('',
131 where the \*(``*\*('' is replaced by the precision argument.
132 .IP
133 For details of the precision handling see \fBprintf\fR(3).
134 .RE
135 .TP 5
136 TYPE_REGEXP
137 Regular expression data.
138 Requires a regular expression \fB(char *)\fR third argument.
139 The data is valid if the regular expression matches it.
140 .IP
141 Regular expressions
142 are in the format of \fBregcomp\fR and \fBregexec\fR.
143 .IP
144 The regular expression must match the whole field.
145 If you have for example, an eight character wide field,
146 a regular expression "^[0\-9]*$" always
147 means that you have to fill all eight positions with digits.
148 If you want to allow fewer digits,
149 you may use for example "^[0\-9]* *$" which is good for
150 trailing spaces (up to an empty field),
151 or "^ *[0\-9]* *$" which is good for
152 leading and trailing spaces around the digits.
153 .TP 5
154 TYPE_IPV4
155 An Internet Protocol Version 4 address.
156 This requires no additional argument.
157 The library checks whether or not the buffer has the form a.b.c.d,
158 where a,b,c and d are numbers between 0 and 255.
159 Trailing blanks in the buffer are ignored.
160 The address itself is not validated.
161 .IP
162 This is an ncurses extension;
163 this field type may not be available in other curses implementations.
164 .PP
165 It is possible to set up new programmer-defined field types.
166 See the \fBform_fieldtype\fR(3X) manual page.
167 .SH RETURN VALUE
168 The functions \fBfield_type\fR and \fBfield_arg\fR return \fBNULL\fR on error.
169 The function \fBset_field_type\fR returns one of the following:
170 .TP 5
171 .B E_OK
172 The routine succeeded.
173 .TP 5
174 .B E_SYSTEM_ERROR
175 System error occurred (see \fBerrno\fR(3)).
176 .SH SEE ALSO
177 \fBcurses\fR(3X),
178 \fBform\fR(3X),
179 \fBform_variables\fR(3X).
180 .SH NOTES
181 The header file \fB<form.h>\fR automatically includes the header file
182 \fB<curses.h>\fR.
183 .SH PORTABILITY
184 These routines emulate the System V forms library.
185 They were not supported on
186 Version 7 or BSD versions.
187 .SH AUTHORS
188 Juergen Pfeifer.
189 Manual pages and adaptation for new curses by Eric S. Raymond.