File: Zend_Validate-Date.xml

package info (click to toggle)
zendframework 1.12.9%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: jessie-kfreebsd
  • size: 133,584 kB
  • sloc: xml: 1,311,829; php: 570,173; sh: 170; makefile: 125; sql: 121
file content (108 lines) | stat: -rw-r--r-- 3,677 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
<?xml version="1.0" encoding="UTF-8"?>
<!-- Reviewed: no -->
<sect2 id="zend.validate.set.date">
    <title>Date</title>

    <para>
        <classname>Zend_Validate_Date</classname> allows you to validate if a given value contains
        a date. This validator validates also localized input.
    </para>

    <sect3 id="zend.validate.set.date.options">
        <title>Supported options for Zend_Validate_Date</title>

        <para>
            The following options are supported for <classname>Zend_Validate_Date</classname>:
        </para>

        <itemizedlist>
            <listitem>
                <para>
                    <emphasis><property>format</property></emphasis>: Sets the format which is used
                    to write the date.
                </para>
            </listitem>

            <listitem>
                <para>
                    <emphasis><property>locale</property></emphasis>: Sets the locale which will be
                    used to validate date values.
                </para>
            </listitem>
        </itemizedlist>
    </sect3>

    <sect3 id="zend.validate.set.date.basic">
        <title>Default date validation</title>

        <para>
            The easiest way to validate a date is by using the default date format. It is used when
            no locale and no format has been given.
        </para>

        <programlisting language="php"><![CDATA[
$validator = new Zend_Validate_Date();

$validator->isValid('2000-10-10');   // returns true
$validator->isValid('10.10.2000'); // returns false
]]></programlisting>

        <para>
            The default date format for <classname>Zend_Validate_Date</classname> is 'yyyy-MM-dd'.
        </para>
    </sect3>

    <sect3 id="zend.validate.set.date.localized">
        <title>Localized date validation</title>

        <para>
            <classname>Zend_Validate_Date</classname> validates also dates which are given in a
            localized format. By using the <property>locale</property> option you can define the
            locale which the date format should use for validation.
        </para>

        <programlisting language="php"><![CDATA[
$validator = new Zend_Validate_Date(array('locale' => 'de'));

$validator->isValid('10.Feb.2010'); // returns true
$validator->isValid('10.May.2010'); // returns false
]]></programlisting>

        <para>
            The <property>locale</property> option sets the default date format. In the above
            example this is 'dd.MM.yyyy' which is defined as default date format for 'de'.
        </para>
    </sect3>

    <sect3 id="zend.validate.set.date.formats">
        <title>Self defined date validation</title>

        <para>
            <classname>Zend_Validate_Date</classname> supports also self defined date formats.
            When you want to validate such a date you can use the <property>format</property>
            option.
        </para>

        <programlisting language="php"><![CDATA[
$validator = new Zend_Validate_Date(array('format' => 'yyyy'));

$validator->isValid('2010'); // returns true
$validator->isValid('May');  // returns false
]]></programlisting>

        <para>
            Of course you can combine <property>format</property> and <property>locale</property>.
            In this case you can also use localized month or daynames.
        </para>

        <programlisting language="php"><![CDATA[
$validator = new Zend_Validate_Date(array('format' => 'yyyy MMMM', 'locale' => 'de'));

$validator->isValid('2010 Dezember'); // returns true
$validator->isValid('2010 June');     // returns false
]]></programlisting>
    </sect3>
</sect2>
<!--
vim:se ts=4 sw=4 et:
-->