Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 1 | .\"*************************************************************************** |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame^] | 2 | .\" Copyright (c) 1998-2006,2010 Free Software Foundation, Inc. * |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 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 | .\" |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame^] | 29 | .\" $Id: form_field_validation.3x,v 1.20 2010/12/04 18:38:55 tom Exp $ |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 30 | .TH form_field_validation 3X "" |
| 31 | .SH NAME |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame^] | 32 | \fBform_field_validation\fR \- data type validation for fields |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 33 | .SH SYNOPSIS |
| 34 | \fB#include <form.h>\fR |
| 35 | .br |
| 36 | int set_field_type(FIELD *field, FIELDTYPE *type, ...); |
| 37 | .br |
| 38 | FIELDTYPE *field_type(const FIELD *field); |
| 39 | .br |
| 40 | void *field_arg(const FIELD *field); |
| 41 | .sp |
| 42 | FIELDTYPE *TYPE_ALNUM; |
| 43 | .br |
| 44 | FIELDTYPE *TYPE_ALPHA; |
| 45 | .br |
| 46 | FIELDTYPE *TYPE_ENUM; |
| 47 | .br |
| 48 | FIELDTYPE *TYPE_INTEGER; |
| 49 | .br |
| 50 | FIELDTYPE *TYPE_NUMERIC; |
| 51 | .br |
| 52 | FIELDTYPE *TYPE_REGEXP; |
| 53 | .br |
| 54 | FIELDTYPE *TYPE_IPV4; |
| 55 | .br |
| 56 | .SH DESCRIPTION |
| 57 | The function \fBset_field_type\fR declares a data type for a given form field. |
| 58 | This is the type checked by validation functions. |
| 59 | The predefined types are as follows: |
| 60 | .TP 5 |
| 61 | TYPE_ALNUM |
| 62 | Alphanumeric data. Requires a third \fBint\fR argument, a minimum field width. |
| 63 | .TP 5 |
| 64 | TYPE_ALPHA |
| 65 | Character data. Requires a third \fBint\fR argument, a minimum field width. |
| 66 | .TP 5 |
| 67 | TYPE_ENUM |
| 68 | Accept one of a specified set of strings. Requires a third \fB(char **)\fR |
| 69 | argument pointing to a string list; a fourth \fBint\fR flag argument to enable |
| 70 | case-sensitivity; and a fifth \fBint\fR flag argument specifying whether a partial |
| 71 | match must be a unique one (if this flag is off, a prefix matches the first |
| 72 | of any set of more than one list elements with that prefix). Please notice |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame^] | 73 | that the string list is copied. So you may use a list that lives in automatic variables on the stack. |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 74 | .TP 5 |
| 75 | TYPE_INTEGER |
| 76 | Integer data, parsable to an integer by \fBatoi(3)\fR. Requires a third |
| 77 | \fBint\fR argument controlling the precision, a fourth \fBlong\fR argument |
| 78 | constraining minimum value, and a fifth \fBlong\fR constraining maximum value. |
| 79 | If the maximum value is less than or equal to the minimum value, the range is |
| 80 | simply ignored. On return the field buffer is formatted according to the |
| 81 | \fBprintf\fR format specification ".*ld", where the '*' is replaced by the |
| 82 | precision argument. |
| 83 | For details of the precision handling see \fBprintf's\fR man-page. |
| 84 | .TP 5 |
| 85 | TYPE_NUMERIC |
| 86 | Numeric data (may have a decimal-point part). Requires a third |
| 87 | \fBint\fR argument controlling the precision, a fourth \fBdouble\fR |
| 88 | argument constraining minimum value, and a fifth \fBdouble\fR constraining |
| 89 | maximum value. If your system supports locales, the decimal point character |
| 90 | to be used must be the one specified by your locale. |
| 91 | If the maximum value is less than or equal to the minimum value, the range is |
| 92 | simply ignored. On return the field buffer is formatted according to the |
| 93 | \fBprintf\fR format specification ".*f", where the '*' is replaced by the |
| 94 | precision argument. |
| 95 | For details of the precision handling see \fBprintf's\fR man-page. |
| 96 | .TP 5 |
| 97 | TYPE_REGEXP |
| 98 | Regular expression data. Requires a regular expression \fB(char *)\fR third argument; |
| 99 | the data is valid if the regular expression matches it. Regular expressions |
| 100 | are in the format of \fBregcomp\fR and \fBregexec\fR. Please notice |
| 101 | that the regular expression must match the whole field. If you have for |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame^] | 102 | example an eight character wide field, a regular expression "^[0\-9]*$" always |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 103 | means that you have to fill all eight positions with digits. If you want to |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame^] | 104 | allow fewer digits, you may use for example "^[0\-9]* *$" which is good for |
| 105 | trailing spaces (up to an empty field), or "^ *[0\-9]* *$" which is good for |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 106 | leading and trailing spaces around the digits. |
| 107 | .TP 5 |
| 108 | TYPE_IPV4 |
| 109 | An Internet Protocol Version 4 address. This requires no additional argument. It |
| 110 | is checked whether or not the buffer has the form a.b.c.d, where a,b,c and d are |
| 111 | numbers between 0 and 255. Trailing blanks in the buffer are ignored. The address |
| 112 | itself is not validated. Please note that this is an ncurses extension. This |
| 113 | field type may not be available in other curses implementations. |
| 114 | .PP |
| 115 | It is possible to set up new programmer-defined field types. See the |
| 116 | \fBform_fieldtype\fR(3X) manual page. |
| 117 | .SH RETURN VALUE |
| 118 | The functions \fBfield_type\fR and \fBfield_arg\fR return \fBNULL\fR on |
| 119 | error. The function \fBset_field_type\fR returns one of the following: |
| 120 | .TP 5 |
| 121 | .B E_OK |
| 122 | The routine succeeded. |
| 123 | .TP 5 |
| 124 | .B E_SYSTEM_ERROR |
| 125 | System error occurred (see \fBerrno\fR). |
| 126 | .SH SEE ALSO |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame^] | 127 | \fBcurses\fR(3X), |
| 128 | \fBform\fR(3X), |
| 129 | \fBform_variables\fR(3X). |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 130 | .SH NOTES |
| 131 | The header file \fB<form.h>\fR automatically includes the header file |
| 132 | \fB<curses.h>\fR. |
| 133 | .SH PORTABILITY |
| 134 | These routines emulate the System V forms library. They were not supported on |
| 135 | Version 7 or BSD versions. |
| 136 | .SH AUTHORS |
| 137 | Juergen Pfeifer. Manual pages and adaptation for new curses by Eric |
| 138 | S. Raymond. |