| 1 |
.\"*************************************************************************** |
| 2 |
.\" Copyright 2018-2024,2025 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.62 2025/08/16 19:11:47 tom Exp $ |
| 31 |
.TH field_validation 3FORM 2025-08-16 "ncurses 6.6" "Library calls" |
| 32 |
.ie \n(.g \{\ |
| 33 |
.ds `` \(lq |
| 34 |
.ds '' \(rq |
| 35 |
.\} |
| 36 |
.el \{\ |
| 37 |
.ie t .ds `` `` |
| 38 |
.el .ds `` "" |
| 39 |
.ie t .ds '' '' |
| 40 |
.el .ds '' "" |
| 41 |
.\} |
| 42 |
. |
| 43 |
.de bP |
| 44 |
.ie n .IP \(bu 4 |
| 45 |
.el .IP \(bu 2 |
| 46 |
.. |
| 47 |
.SH NAME |
| 48 |
\fBform_field_validation\fP \- |
| 49 |
data type validation for fields |
| 50 |
.SH SYNOPSIS |
| 51 |
.nf |
| 52 |
\fB#include <form.h> |
| 53 |
.PP |
| 54 |
\fBvoid *field_arg(const FIELD *\fIfield\fP); |
| 55 |
\fBFIELDTYPE *field_type(const FIELD *\fIfield\fP); |
| 56 |
\fBint set_field_type(FIELD *\fIfield\fP, FIELDTYPE *\fItype\fP, ...); |
| 57 |
.PP |
| 58 |
\fI/* field types */\fP |
| 59 |
\fBFIELDTYPE *TYPE_ALNUM; |
| 60 |
\fBFIELDTYPE *TYPE_ALPHA; |
| 61 |
\fBFIELDTYPE *TYPE_ENUM; |
| 62 |
\fBFIELDTYPE *TYPE_INTEGER; |
| 63 |
\fBFIELDTYPE *TYPE_NUMERIC; |
| 64 |
\fBFIELDTYPE *TYPE_REGEXP; |
| 65 |
\fBFIELDTYPE *TYPE_IPV4; |
| 66 |
.fi |
| 67 |
.SH DESCRIPTION |
| 68 |
By default, no validation is done on form fields. |
| 69 |
You can associate a form with a \fIfield type\fP, |
| 70 |
making the form library validate input. |
| 71 |
.SS field_arg |
| 72 |
Returns a pointer to the field's argument block. |
| 73 |
The \fIargument block\fP is an opaque structure containing |
| 74 |
a copy of the arguments provided in a \fBset_field_type\fP call. |
| 75 |
.SS field_type |
| 76 |
Returns a pointer to the \fIfield type\fP associated with the form field, |
| 77 |
i.e., by calling \fBset_field_type\fP. |
| 78 |
.SS set_field_type |
| 79 |
The function \fBset_field_type\fP associates |
| 80 |
a field type with a given form field. |
| 81 |
This is the type checked by validation functions. |
| 82 |
Most field types are configurable, |
| 83 |
via arguments which the caller provides when calling \fBset_field_type\fP. |
| 84 |
.SH "FIELD TYPES" |
| 85 |
The |
| 86 |
.I form |
| 87 |
library defines several field types. |
| 88 |
They are implemented via the \fBFIELDTYPE\fP data structure, |
| 89 |
which contains several pointers to functions. |
| 90 |
.PP |
| 91 |
See the \fBfieldtype\fP(3FORM) manual page, |
| 92 |
which describes functions which can be used to construct |
| 93 |
a field-type dynamically. |
| 94 |
.PP |
| 95 |
The predefined types are as follows: |
| 96 |
.SS TYPE_ALNUM |
| 97 |
Alphanumeric data. |
| 98 |
Required parameter: |
| 99 |
.bP |
| 100 |
a third \fBint\fP argument, a minimum field width. |
| 101 |
.SS TYPE_ALPHA |
| 102 |
Character data. |
| 103 |
Required parameter: |
| 104 |
.bP |
| 105 |
a third \fBint\fP argument, a minimum field width. |
| 106 |
.SS TYPE_ENUM |
| 107 |
Accept one of a specified set of strings. |
| 108 |
Required parameters: |
| 109 |
.bP |
| 110 |
a third \fB(char **)\fP argument pointing to a string list; |
| 111 |
.bP |
| 112 |
a fourth \fBint\fP flag argument to enable case-sensitivity; |
| 113 |
.bP |
| 114 |
a fifth \fBint\fP flag argument specifying whether a partial |
| 115 |
match must be a unique one. |
| 116 |
If this flag is off, a prefix matches the first |
| 117 |
of any set of more than one list elements with that prefix. |
| 118 |
.PP |
| 119 |
The library copies the string list, |
| 120 |
so you may use a list that lives in automatic variables on the stack. |
| 121 |
.SS TYPE_INTEGER |
| 122 |
Integer data, parsable to an integer by \fBatoi\fP(3). |
| 123 |
Required parameters: |
| 124 |
.bP |
| 125 |
a third \fBint\fP argument controlling the precision, |
| 126 |
.bP |
| 127 |
a fourth \fBlong\fP argument constraining minimum value, |
| 128 |
.bP |
| 129 |
a fifth \fBlong\fP constraining maximum value. |
| 130 |
If the maximum value is less than or equal to the minimum value, the range is |
| 131 |
simply ignored. |
| 132 |
.PP |
| 133 |
On return, the field buffer is formatted according to the |
| 134 |
\fBprintf\fP format specification \*(``.*ld\*('', |
| 135 |
where the \*(``*\*('' is replaced by the precision argument. |
| 136 |
.PP |
| 137 |
For details of the precision handling see \fBprintf\fP(3). |
| 138 |
.SS TYPE_NUMERIC |
| 139 |
Numeric data (may have a decimal-point part). |
| 140 |
Required parameters: |
| 141 |
.bP |
| 142 |
a third \fBint\fP argument controlling the precision, |
| 143 |
.bP |
| 144 |
a fourth \fBdouble\fP argument constraining minimum value, |
| 145 |
.bP |
| 146 |
and a fifth \fBdouble\fP constraining maximum value. |
| 147 |
If your system supports locales, |
| 148 |
the decimal point character must be the one specified by your locale. |
| 149 |
If the maximum value is less than or equal to the minimum value, |
| 150 |
the range is simply ignored. |
| 151 |
.PP |
| 152 |
On return, the field buffer is formatted according to the |
| 153 |
\fBprintf\fP format specification \*(``.*f\*('', |
| 154 |
where the \*(``*\*('' is replaced by the precision argument. |
| 155 |
.PP |
| 156 |
For details of the precision handling see \fBprintf\fP(3). |
| 157 |
.SS TYPE_REGEXP |
| 158 |
Regular expression data. |
| 159 |
Required parameter: |
| 160 |
.bP |
| 161 |
a third argument, a regular expression \fB(char *)\fP string. |
| 162 |
The data is valid if the regular expression matches it. |
| 163 |
.PP |
| 164 |
Regular expressions |
| 165 |
are in the format of \fBregcomp\fP and \fBregexec\fP. |
| 166 |
.PP |
| 167 |
The regular expression must match the whole field. |
| 168 |
If you have for example, an eight character wide field, |
| 169 |
a regular expression "^[0\-9]*$" always |
| 170 |
means that you have to fill all eight positions with digits. |
| 171 |
If you want to allow fewer digits, |
| 172 |
you may use for example "^[0\-9]* *$" which is good for |
| 173 |
trailing spaces (up to an empty field), |
| 174 |
or "^ *[0\-9]* *$" which is good for |
| 175 |
leading and trailing spaces around the digits. |
| 176 |
.SS TYPE_IPV4 |
| 177 |
An Internet Protocol Version\ 4 address. |
| 178 |
Required parameter: |
| 179 |
.bP |
| 180 |
none |
| 181 |
.PP |
| 182 |
The form library checks whether or not the buffer has the form \fIa.b.c.d\fP, |
| 183 |
where \fIa\fP, \fIb\fP, \fIc\fP, and \fId\fP are numbers in the range 0 to 255. |
| 184 |
Trailing blanks in the buffer are ignored. |
| 185 |
The address itself is not validated. |
| 186 |
.PP |
| 187 |
This is an \fI\%ncurses\fP extension; |
| 188 |
this field type may not be available in other curses implementations. |
| 189 |
.PP |
| 190 |
It is possible to set up new programmer-defined field types. |
| 191 |
.SH RETURN VALUE |
| 192 |
The functions \fBfield_type\fP and \fBfield_arg\fP return |
| 193 |
.I NULL |
| 194 |
on error. |
| 195 |
The function \fBset_field_type\fP returns one of the following: |
| 196 |
.TP 5 |
| 197 |
.B E_OK |
| 198 |
The routine succeeded. |
| 199 |
.TP 5 |
| 200 |
.B E_SYSTEM_ERROR |
| 201 |
System error occurred (see \fBerrno\fP(3)). |
| 202 |
.SH PORTABILITY |
| 203 |
These routines emulate the System V forms library. |
| 204 |
They were not supported on |
| 205 |
Version 7 or BSD versions. |
| 206 |
.SH AUTHORS |
| 207 |
Juergen Pfeifer. |
| 208 |
Manual pages and adaptation for new curses by Eric S. Raymond. |
| 209 |
.SH SEE ALSO |
| 210 |
\fB\%ncurses\fP(3NCURSES), |
| 211 |
\fB\%form\fP(3FORM), |
| 212 |
\fB\%fieldtype\fP(3FORM), |
| 213 |
\fB\%form_variables\fP(3FORM) |