Zend_Validate-Float.xml 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!-- Reviewed: no -->
  3. <sect2 id="zend.validate.set.float">
  4. <title>Float</title>
  5. <para>
  6. <classname>Zend_Validate_Float</classname> allows you to validate if a given value contains
  7. a floating-point value. This validator validates also localized input.
  8. </para>
  9. <sect3 id="zend.validate.set.float.options">
  10. <title>Supported options for Zend_Validate_Float</title>
  11. <para>
  12. The following options are supported for <classname>Zend_Validate_Float</classname>:
  13. </para>
  14. <itemizedlist>
  15. <listitem>
  16. <para>
  17. <emphasis><property>locale</property></emphasis>: Sets the locale which will be
  18. used to validate localized float values.
  19. </para>
  20. </listitem>
  21. </itemizedlist>
  22. </sect3>
  23. <sect3 id="zend.validate.set.float.basic">
  24. <title>Simple float validation</title>
  25. <para>
  26. The simplest way to validate a float is by using the system settings. When no option
  27. is used, the environment locale is used for validation:
  28. </para>
  29. <programlisting language="php"><![CDATA[
  30. $validator = new Zend_Validate_Float();
  31. $validator->isValid(1234.5); // returns true
  32. $validator->isValid('10a01'); // returns false
  33. $validator->isValid('1,234.5'); // returns true
  34. ]]></programlisting>
  35. <para>
  36. In the above example we expected that our environment is set to "en" as locale.
  37. </para>
  38. </sect3>
  39. <sect3 id="zend.validate.set.float.localized">
  40. <title>Localized float validation</title>
  41. <para>
  42. Often it's useful to be able to validate also localized values. Float values are often
  43. written different in other countries. For example using english you will write "1.5".
  44. In german you may write "1,5" and in other languages you may use grouping.
  45. </para>
  46. <para>
  47. <classname>Zend_Validate_Float</classname> is able to validate such notations. But it is
  48. limited to the locale you set. See the following code:
  49. </para>
  50. <programlisting language="php"><![CDATA[
  51. $validator = new Zend_Validate_Float(array('locale' => 'de'));
  52. $validator->isValid(1234.5); // returns true
  53. $validator->isValid("1 234,5"); // returns false
  54. $validator->isValid("1.234"); // returns true
  55. ]]></programlisting>
  56. <para>
  57. As you can see, by using a locale, your input is validated localized. Using a different
  58. notation you get a <constant>FALSE</constant> when the locale forces a different
  59. notation.
  60. </para>
  61. <para>
  62. The locale can also be set afterwards by using <methodname>setLocale()</methodname> and
  63. retrieved by using <methodname>getLocale()</methodname>.
  64. </para>
  65. </sect3>
  66. </sect2>
  67. <!--
  68. vim:se ts=4 sw=4 et:
  69. -->