form_field_validation.3x.html 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
  2. <!--
  3. ****************************************************************************
  4. * Copyright (c) 1998-2003,2006 Free Software Foundation, Inc. *
  5. * *
  6. * Permission is hereby granted, free of charge, to any person obtaining a *
  7. * copy of this software and associated documentation files (the *
  8. * "Software"), to deal in the Software without restriction, including *
  9. * without limitation the rights to use, copy, modify, merge, publish, *
  10. * distribute, distribute with modifications, sublicense, and/or sell *
  11. * copies of the Software, and to permit persons to whom the Software is *
  12. * furnished to do so, subject to the following conditions: *
  13. * *
  14. * The above copyright notice and this permission notice shall be included *
  15. * in all copies or substantial portions of the Software. *
  16. * *
  17. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
  18. * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
  19. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
  20. * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
  21. * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
  22. * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
  23. * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
  24. * *
  25. * Except as contained in this notice, the name(s) of the above copyright *
  26. * holders shall not be used in advertising or otherwise to promote the *
  27. * sale, use or other dealings in this Software without prior written *
  28. * authorization. *
  29. ****************************************************************************
  30. * @Id: form_field_validation.3x,v 1.16 2006/12/24 16:08:08 tom Exp @
  31. -->
  32. <HTML>
  33. <HEAD>
  34. <TITLE>form_field_validation 3x</TITLE>
  35. <link rev=made href="mailto:bug-ncurses@gnu.org">
  36. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  37. </HEAD>
  38. <BODY>
  39. <H1>form_field_validation 3x</H1>
  40. <HR>
  41. <PRE>
  42. <!-- Manpage converted by man2html 3.0.1 -->
  43. <STRONG><A HREF="form_field_validation.3x.html">form_field_validation(3x)</A></STRONG> <STRONG><A HREF="form_field_validation.3x.html">form_field_validation(3x)</A></STRONG>
  44. </PRE>
  45. <H2>NAME</H2><PRE>
  46. <STRONG>form_field_validation</STRONG> - data type validation for fields
  47. </PRE>
  48. <H2>SYNOPSIS</H2><PRE>
  49. <STRONG>#include</STRONG> <STRONG>&lt;form.h&gt;</STRONG>
  50. int set_field_type(FIELD *field, FIELDTYPE *type, ...);
  51. FIELDTYPE *field_type(const FIELD *field);
  52. void *field_arg(const FIELD *field);
  53. FIELDTYPE *TYPE_ALNUM;
  54. FIELDTYPE *TYPE_ALPHA;
  55. FIELDTYPE *TYPE_ENUM;
  56. FIELDTYPE *TYPE_INTEGER;
  57. FIELDTYPE *TYPE_NUMERIC;
  58. FIELDTYPE *TYPE_REGEXP;
  59. FIELDTYPE *TYPE_IPV4;
  60. </PRE>
  61. <H2>DESCRIPTION</H2><PRE>
  62. The function <STRONG>set_field_type</STRONG> declares a data type for a
  63. given form field. This is the type checked by validation
  64. functions. The predefined types are as follows:
  65. TYPE_ALNUM
  66. Alphanumeric data. Requires a third <STRONG>int</STRONG> argument, a
  67. minimum field width.
  68. TYPE_ALPHA
  69. Character data. Requires a third <STRONG>int</STRONG> argument, a
  70. minimum field width.
  71. TYPE_ENUM
  72. Accept one of a specified set of strings. Requires a
  73. third <STRONG>(char</STRONG> <STRONG>**)</STRONG> argument pointing to a string list; a
  74. fourth <STRONG>int</STRONG> flag argument to enable case-sensitivity;
  75. and a fifth <STRONG>int</STRONG> flag argument specifying whether a
  76. partial match must be a unique one (if this flag is
  77. off, a prefix matches the first of any set of more
  78. than one list elements with that prefix). Please
  79. notice that the string list is not copied, only a
  80. reference to it is stored in the field. So you should
  81. avoid using a list that lives in automatic variables
  82. on the stack.
  83. TYPE_INTEGER
  84. Integer data, parsable to an integer by <STRONG>atoi(3)</STRONG>.
  85. Requires a third <STRONG>int</STRONG> argument controlling the preci-
  86. sion, a fourth <STRONG>long</STRONG> argument constraining minimum
  87. value, and a fifth <STRONG>long</STRONG> constraining maximum value.
  88. If the maximum value is less than or equal to the
  89. minimum value, the range is simply ignored. On return
  90. the field buffer is formatted according to the <STRONG>printf</STRONG>
  91. format specification ".*ld", where the '*' is
  92. replaced by the precision argument. For details of
  93. the precision handling see <STRONG>printf's</STRONG> man-page.
  94. TYPE_NUMERIC
  95. Numeric data (may have a decimal-point part).
  96. Requires a third <STRONG>int</STRONG> argument controlling the preci-
  97. sion, a fourth <STRONG>double</STRONG> argument constraining minimum
  98. value, and a fifth <STRONG>double</STRONG> constraining maximum value.
  99. If your system supports locales, the decimal point
  100. character to be used must be the one specified by
  101. your locale. If the maximum value is less than or
  102. equal to the minimum value, the range is simply
  103. ignored. On return the field buffer is formatted
  104. according to the <STRONG>printf</STRONG> format specification ".*f",
  105. where the '*' is replaced by the precision argument.
  106. For details of the precision handling see <STRONG>printf's</STRONG>
  107. man-page.
  108. TYPE_REGEXP
  109. Regular expression data. Requires a regular expres-
  110. sion <STRONG>(char</STRONG> <STRONG>*)</STRONG> third argument; the data is valid if
  111. the regular expression matches it. Regular expres-
  112. sions are in the format of <STRONG>regcomp</STRONG> and <STRONG>regexec</STRONG>.
  113. Please notice that the regular expression must match
  114. the whole field. If you have for example an eight
  115. character wide field, a regular expression "^[0-9]*$"
  116. always means that you have to fill all eight posi-
  117. tions with digits. If you want to allow fewer digits,
  118. you may use for example "^[0-9]* *$" which is good
  119. for trailing spaces (up to an empty field), or "^
  120. *[0-9]* *$" which is good for leading and trailing
  121. spaces around the digits.
  122. TYPE_IPV4
  123. An Internet Protocol Version 4 address. This requires
  124. no additional argument. It is checked whether or not
  125. the buffer has the form a.b.c.d, where a,b,c and d
  126. are numbers between 0 and 255. Trailing blanks in the
  127. buffer are ignored. The address itself is not vali-
  128. dated. Please note that this is an ncurses extension.
  129. This field type may not be available in other curses
  130. implementations.
  131. It is possible to set up new programmer-defined field
  132. types. See the <STRONG><A HREF="form_fieldtype.3x.html">form_fieldtype(3x)</A></STRONG> manual page.
  133. </PRE>
  134. <H2>RETURN VALUE</H2><PRE>
  135. The functions <STRONG>field_type</STRONG> and <STRONG>field_arg</STRONG> return <STRONG>NULL</STRONG> on
  136. error. The function <STRONG>set_field_type</STRONG> returns one of the fol-
  137. lowing:
  138. <STRONG>E_OK</STRONG> The routine succeeded.
  139. <STRONG>E_SYSTEM_ERROR</STRONG>
  140. System error occurred (see <STRONG>errno</STRONG>).
  141. </PRE>
  142. <H2>SEE ALSO</H2><PRE>
  143. <STRONG><A HREF="ncurses.3x.html">curses(3x)</A></STRONG>, <STRONG><A HREF="form.3x.html">form(3x)</A></STRONG>.
  144. </PRE>
  145. <H2>NOTES</H2><PRE>
  146. The header file <STRONG>&lt;form.h&gt;</STRONG> automatically includes the header
  147. file <STRONG>&lt;curses.h&gt;</STRONG>.
  148. </PRE>
  149. <H2>PORTABILITY</H2><PRE>
  150. These routines emulate the System V forms library. They
  151. were not supported on Version 7 or BSD versions.
  152. </PRE>
  153. <H2>AUTHORS</H2><PRE>
  154. Juergen Pfeifer. Manual pages and adaptation for new
  155. curses by Eric S. Raymond.
  156. <STRONG><A HREF="form_field_validation.3x.html">form_field_validation(3x)</A></STRONG>
  157. </PRE>
  158. <HR>
  159. <ADDRESS>
  160. Man(1) output converted with
  161. <a href="http://www.oac.uci.edu/indiv/ehood/man2html.html">man2html</a>
  162. </ADDRESS>
  163. </BODY>
  164. </HTML>