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