Zend_Validate-Set.xml 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!-- Reviewed: no -->
  3. <sect1 id="zend.validate.set" xmlns:xi="http://www.w3.org/2001/XInclude">
  4. <title>Standard Validation Classes</title>
  5. <para>
  6. Zend Framework comes with a standard set of validation classes, which are ready for you to use.
  7. </para>
  8. <sect2 id="zend.validate.set.alnum">
  9. <title>Alnum</title>
  10. <para>
  11. Returns <code>true</code> if and only if <code>$value</code> contains only alphabetic and digit characters.
  12. This validator includes an option to also consider white space characters as valid.
  13. </para>
  14. <note>
  15. <para>
  16. The alphabetic characters mean characters that makes up words in each language.
  17. However, the English alphabet is treated as the alphabetic characters in following languages: Chinese, Japanese, Korean.
  18. The language is specified by Zend_Locale.
  19. </para>
  20. </note>
  21. </sect2>
  22. <sect2 id="zend.validate.set.alpha">
  23. <title>Alpha</title>
  24. <para>
  25. Returns <code>true</code> if and only if <code>$value</code> contains only alphabetic characters. This
  26. validator includes an option to also consider white space characters as valid.
  27. </para>
  28. </sect2>
  29. <sect2 id="zend.validate.set.barcode">
  30. <title>Barcode</title>
  31. <para>
  32. This validator is instantiated with a barcode type against which you wish to validate a barcode value.
  33. It currently supports "<code>UPC-A</code>" (Universal Product Code) and "<code>EAN-13</code>" (European
  34. Article Number) barcode types, and the <code>isValid()</code> method returns true if and only if the input
  35. successfully validates against the barcode validation algorithm. You should remove all characters other
  36. than the digits zero through nine (0-9) from the input value before passing it on to the validator.
  37. </para>
  38. </sect2>
  39. <sect2 id="zend.validate.set.between">
  40. <title>Between</title>
  41. <para>
  42. Returns <code>true</code> if and only if <code>$value</code> is between the minimum and maximum boundary
  43. values. The comparison is inclusive by default (<code>$value</code> may equal a boundary value), though
  44. this may be overridden in order to do a strict comparison, where <code>$value</code> must be strictly
  45. greater than the minimum and strictly less than the maximum.
  46. </para>
  47. </sect2>
  48. <sect2 id="zend.validate.set.ccnum">
  49. <title>Ccnum</title>
  50. <para>
  51. Returns <code>true</code> if and only if <code>$value</code> follows the Luhn algorithm (mod-10 checksum)
  52. for credit card numbers.
  53. </para>
  54. </sect2>
  55. <sect2 id="zend.validate.set.date">
  56. <title>Date</title>
  57. <para>
  58. Returns <code>true</code> if <code>$value</code> is a valid date of the format <code>YYYY-MM-DD</code>.
  59. If the optional <code>locale</code> option is set then the date will be validated according to the
  60. set locale. And if the optional <code>format</code> option is set this format is used for the
  61. validation. For details about the optional parameters see
  62. <link linkend="zend.date.others.comparison.table">Zend_Date::isDate()</link>.
  63. </para>
  64. </sect2>
  65. <xi:include href="Zend_Validate-Db.xml" />
  66. <sect2 id="zend.validate.set.digits">
  67. <title>Digits</title>
  68. <para>
  69. Returns <code>true</code> if and only if <code>$value</code> only contains digit characters.
  70. </para>
  71. </sect2>
  72. <xi:include href="Zend_Validate-EmailAddress.xml" />
  73. <sect2 id="zend.validate.set.float">
  74. <title>Float</title>
  75. <para>
  76. Returns <code>true</code> if and only if <code>$value</code> is a floating-point value.
  77. Since Zend Framework 1.8 this validator takes into account the actual locale from browser,
  78. environment or application wide set locale. You can of course use the get/setLocale accessors
  79. to change the used locale or give it while creating a instance of this validator.
  80. </para>
  81. </sect2>
  82. <sect2 id="zend.validate.set.greater_than">
  83. <title>GreaterThan</title>
  84. <para>
  85. Returns <code>true</code> if and only if <code>$value</code> is greater than the minimum boundary.
  86. </para>
  87. </sect2>
  88. <sect2 id="zend.validate.set.hex">
  89. <title>Hex</title>
  90. <para>
  91. Returns <code>true</code> if and only if <code>$value</code> contains only hexadecimal digit characters.
  92. </para>
  93. </sect2>
  94. <xi:include href="Zend_Validate-Hostname.xml" />
  95. <sect2 id="zend.validate.set.iban">
  96. <title>Iban</title>
  97. <para>
  98. Returns <code>true</code> if and only if <code>$value</code> contains a valid IBAN
  99. (International Bank Account Number). IBAN numbers are validated against the country where they are
  100. used and by a checksum.
  101. </para>
  102. <para>
  103. There are two ways to validate IBAN numbers. As first way you can give a locale which represents
  104. a country. Any given IBAN number will then be validated against this country.
  105. </para>
  106. <programlisting role="php"><![CDATA[
  107. $validator = new Zend_Validate_Iban('de_AT');
  108. $iban = 'AT611904300234573201';
  109. if ($validator->isValid($iban)) {
  110. // IBAN appears to be valid
  111. } else {
  112. // IBAN is invalid
  113. foreach ($validator->getMessages() as $message) {
  114. echo "$message\n";
  115. }
  116. }
  117. ]]></programlisting>
  118. <para>
  119. This should be done when you want to validate IBAN numbers for a single countries. The simpler way
  120. of validation is not to give a locale like shown in the next example.
  121. </para>
  122. <programlisting role="php"><![CDATA[
  123. $validator = new Zend_Validate_Iban();
  124. $iban = 'AT611904300234573201';
  125. if ($validator->isValid($iban)) {
  126. // IBAN appears to be valid
  127. } else {
  128. // IBAN is invalid
  129. }
  130. ]]></programlisting>
  131. <para>
  132. But this shows one big problem: When you have to accept only IBAN numbers from one single country,
  133. for example france, then IBAN numbers from other countries would also be valid. Therefor just
  134. remember: When you have to validate a IBAN number against a defined country you should give the
  135. locale. And when you accept all IBAN numbers regardless of any country omit the locale for
  136. simplicity.
  137. </para>
  138. </sect2>
  139. <sect2 id="zend.validate.set.in_array">
  140. <title>InArray</title>
  141. <para>
  142. Returns <code>true</code> if and only if a "needle" <code>$value</code> is contained in a "haystack"
  143. array. If the strict option is <code>true</code>, then the type of <code>$value</code> is also checked.
  144. </para>
  145. </sect2>
  146. <sect2 id="zend.validate.set.int">
  147. <title>Int</title>
  148. <para>
  149. Returns <code>true</code> if and only if <code>$value</code> is a valid integer.
  150. Since Zend Framework 1.8 this validator takes into account the actual locale from browser,
  151. environment or application wide set locale. You can of course use the get/setLocale accessors
  152. to change the used locale or give it while creating a instance of this validator.
  153. </para>
  154. </sect2>
  155. <sect2 id="zend.validate.set.ip">
  156. <title>Ip</title>
  157. <para>
  158. Returns <code>true</code> if and only if <code>$value</code> is a valid IP address.
  159. </para>
  160. </sect2>
  161. <sect2 id="zend.validate.set.less_than">
  162. <title>LessThan</title>
  163. <para>
  164. Returns <code>true</code> if and only if <code>$value</code> is less than the maximum boundary.
  165. </para>
  166. </sect2>
  167. <sect2 id="zend.validate.set.not_empty">
  168. <title>NotEmpty</title>
  169. <para>
  170. Returns <code>true</code> if and only if <code>$value</code> is not an empty value.
  171. </para>
  172. </sect2>
  173. <sect2 id="zend.validate.set.regex">
  174. <title>Regex</title>
  175. <para>
  176. Returns <code>true</code> if and only if <code>$value</code> matches against a regular expression
  177. pattern.
  178. </para>
  179. </sect2>
  180. <xi:include href="Zend_Validate-Sitemap.xml" />
  181. <sect2 id="zend.validate.set.string_length">
  182. <title>StringLength</title>
  183. <para>
  184. Returns <code>true</code> if and only if the string length of <code>$value</code> is at
  185. least a minimum and no greater than a maximum (when the max option is not
  186. <code>null</code>). The <code>setMin()</code> method throws an exception if the minimum
  187. length is set to a value greater than the set maximum length, and the
  188. <code>setMax()</code> method throws an exception if the maximum length is set to a
  189. value less than than the set minimum length. This class supports UTF-8 and other
  190. character encodings, based on the current value of
  191. <ulink url="http://www.php.net/manual/en/ref.iconv.php#iconv.configuration"><code>iconv.internal_encoding</code></ulink>.
  192. If you need a different encoding you can set it with the accessor methods getEncoding
  193. and setEncoding.
  194. </para>
  195. </sect2>
  196. </sect1>
  197. <!--
  198. vim:se ts=4 sw=4 et:
  199. -->