1 <?xml version="1.0" encoding="UTF-8"?>
3 <sect2 id="zend.validate.set.date">
7 <classname>Zend_Validate_Date</classname> allows you to validate if a given value contains
8 a date. This validator validates also localized input.
11 <sect3 id="zend.validate.set.date.options">
12 <title>Supported options for Zend_Validate_Date</title>
15 The following options are supported for <classname>Zend_Validate_Date</classname>:
21 <emphasis><property>format</property></emphasis>: Sets the format which is used
28 <emphasis><property>locale</property></emphasis>: Sets the locale which will be
29 used to validate date values.
35 <sect3 id="zend.validate.set.date.basic">
36 <title>Default date validation</title>
39 The easiest way to validate a date is by using the default date format. It is used when
40 no locale and no format has been given.
43 <programlisting language="php"><![CDATA[
44 $validator = new Zend_Validate_Date();
46 $validator->isValid('2000-10-10'); // returns true
47 $validator->isValid('10.10.2000'); // returns false
51 The default date format for <classname>Zend_Validate_Date</classname> is 'yyyy-MM-dd'.
55 <sect3 id="zend.validate.set.date.localized">
56 <title>Localized date validation</title>
59 <classname>Zend_Validate_Date</classname> validates also dates which are given in a
60 localized format. By using the <property>locale</property> option you can define the
61 locale which the date format should use for validation.
64 <programlisting language="php"><![CDATA[
65 $validator = new Zend_Validate_Date(array('locale' => 'de'));
67 $validator->isValid('10.Feb.2010'); // returns true
68 $validator->isValid('10.May.2010'); // returns false
72 The <property>locale</property> option sets the default date format. In the above
73 example this is 'dd.MM.yyyy' which is defined as default date format for 'de'.
77 <sect3 id="zend.validate.set.date.formats">
78 <title>Self defined date validation</title>
81 <classname>Zend_Validate_Date</classname> supports also self defined date formats.
82 When you want to validate such a date you can use the <property>format</property>
86 <programlisting language="php"><![CDATA[
87 $validator = new Zend_Validate_Date(array('format' => 'yyyy'));
89 $validator->isValid('2010'); // returns true
90 $validator->isValid('May'); // returns false
94 Of course you can combine <property>format</property> and <property>locale</property>.
95 In this case you can also use localized month or daynames.
98 <programlisting language="php"><![CDATA[
99 $validator = new Zend_Validate_Date(array('format' => 'yyyy MMMM', 'locale' => 'de));
101 $validator->isValid('2010 Dezember'); // returns true
102 $validator->isValid('2010 June'); // returns false