Zend_Validate-Date.xml 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!-- Reviewed: no -->
  3. <sect2 id="zend.validate.set.date">
  4. <title>Date</title>
  5. <para>
  6. <classname>Zend_Validate_Date</classname> allows you to validate if a given value contains
  7. a date. This validator validates also localized input.
  8. </para>
  9. <sect3 id="zend.validate.set.date.options">
  10. <title>Supported options for Zend_Validate_Date</title>
  11. <para>
  12. The following options are supported for <classname>Zend_Validate_Date</classname>:
  13. </para>
  14. <itemizedlist>
  15. <listitem>
  16. <para>
  17. <emphasis><property>format</property></emphasis>: Sets the format which is used
  18. to write the date.
  19. </para>
  20. </listitem>
  21. <listitem>
  22. <para>
  23. <emphasis><property>locale</property></emphasis>: Sets the locale which will be
  24. used to validate date values.
  25. </para>
  26. </listitem>
  27. </itemizedlist>
  28. </sect3>
  29. <sect3 id="zend.validate.set.date.basic">
  30. <title>Default date validation</title>
  31. <para>
  32. The easiest way to validate a date is by using the default date format. It is used when
  33. no locale and no format has been given.
  34. </para>
  35. <programlisting language="php"><![CDATA[
  36. $validator = new Zend_Validate_Date();
  37. $validator->isValid('2000-10-10'); // returns true
  38. $validator->isValid('10.10.2000'); // returns false
  39. ]]></programlisting>
  40. <para>
  41. The default date format for <classname>Zend_Validate_Date</classname> is 'yyyy-MM-dd'.
  42. </para>
  43. </sect3>
  44. <sect3 id="zend.validate.set.date.localized">
  45. <title>Localized date validation</title>
  46. <para>
  47. <classname>Zend_Validate_Date</classname> validates also dates which are given in a
  48. localized format. By using the <property>locale</property> option you can define the
  49. locale which the date format should use for validation.
  50. </para>
  51. <programlisting language="php"><![CDATA[
  52. $validator = new Zend_Validate_Date(array('locale' => 'de'));
  53. $validator->isValid('10.Feb.2010'); // returns true
  54. $validator->isValid('10.May.2010'); // returns false
  55. ]]></programlisting>
  56. <para>
  57. The <property>locale</property> option sets the default date format. In the above
  58. example this is 'dd.MM.yyyy' which is defined as default date format for 'de'.
  59. </para>
  60. </sect3>
  61. <sect3 id="zend.validate.set.date.formats">
  62. <title>Self defined date validation</title>
  63. <para>
  64. <classname>Zend_Validate_Date</classname> supports also self defined date formats.
  65. When you want to validate such a date you can use the <property>format</property>
  66. option.
  67. </para>
  68. <programlisting language="php"><![CDATA[
  69. $validator = new Zend_Validate_Date(array('format' => 'yyyy'));
  70. $validator->isValid('2010'); // returns true
  71. $validator->isValid('May'); // returns false
  72. ]]></programlisting>
  73. <para>
  74. Of course you can combine <property>format</property> and <property>locale</property>.
  75. In this case you can also use localized month or daynames.
  76. </para>
  77. <programlisting language="php"><![CDATA[
  78. $validator = new Zend_Validate_Date(array('format' => 'yyyy MMMM', 'locale' => 'de'));
  79. $validator->isValid('2010 Dezember'); // returns true
  80. $validator->isValid('2010 June'); // returns false
  81. ]]></programlisting>
  82. </sect3>
  83. </sect2>
  84. <!--
  85. vim:se ts=4 sw=4 et:
  86. -->