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