Zend_Validate-Set.xml 10 KB

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