Przeglądaj źródła

[ZF-8976] Zend_Validate_Int:

- added new manual section

git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@21556 44c647ce-9c0f-0410-b52a-842ac1e357ba
thomas 16 lat temu
rodzic
commit
d2218a0181

+ 88 - 0
documentation/manual/en/module_specs/Zend_Validate-Int.xml

@@ -0,0 +1,88 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- Reviewed: no -->
+<sect2 id="zend.validate.set.int">
+    <title>Int</title>
+
+    <para>
+        <classname>Zend_Validate_Int</classname> validates if a given value is an integer. Also
+        localized integer values are recognised and can be validated.
+    </para>
+
+    <sect3 id="zend.validate.set.int.options">
+        <title>Supported options for Zend_Validate_Int</title>
+
+        <para>
+            The following options are supported for <classname>Zend_Validate_Int</classname>:
+        </para>
+
+        <itemizedlist>
+            <listitem>
+                <para>
+                    <emphasis><property>locale</property></emphasis>: Sets the locale which will be
+                    used to validate localized integers.
+                </para>
+            </listitem>
+        </itemizedlist>
+    </sect3>
+
+    <sect3 id="zend.validate.set.int.basic">
+        <title>Simple integer validation</title>
+
+        <para>
+            The simplest way to validate an integer is by using the system settings. When no option
+            is used, the environment locale is used for validation:
+        </para>
+
+        <programlisting language="php"><![CDATA[
+$validator = new Zend_Validate_Int();
+
+$validator->isValid(1234);   // returns true
+$validator->isValid(1234.5); // returns false
+$validator->isValid('1,234'); // returns true
+]]></programlisting>
+
+        <para>
+            In the above example we expected that our environment is set to "en" as locale. As you
+            can see in the third example also grouping is recognised.
+        </para>
+    </sect3>
+
+    <sect3 id="zend.validate.set.int.localized">
+        <title>Localized integer validation</title>
+
+        <para>
+            Often it's useful to be able to validate also localized values. Integer values are often
+            written different in other countries. For example using english you can write "1234" or
+            "1,234". Both are integer values but the grouping is optional. In german for example you
+            may write "1.234" and in french "1 234".
+        </para>
+
+        <para>
+            <classname>Zend_Validate_Int</classname> is able to validate such notations. But it is
+            limited to the locale you set. This means that it not simply strips off the separator,
+            it validates if the correct separator is used. See the following code:
+        </para>
+
+        <programlisting language="php"><![CDATA[
+$validator = new Zend_Validate_Int(array('locale' => 'de'));
+
+$validator->isValid(1234); // returns true
+$validator->isValid("1,234"); // returns false
+$validator->isValid("1.234"); // returns true
+]]></programlisting>
+
+        <para>
+            As you can see, by using a locale, your input is validated localized. Using the english
+            notation you get a <constant>FALSE</constant> when the locale forces a different
+            notation.
+        </para>
+
+        <para>
+            The locale can also be set afterwards by using <methodname>setLocale()</methodname> and
+            retrieved by using <methodname>getLocale()</methodname>.
+        </para>
+    </sect3>
+</sect2>
+<!--
+vim:se ts=4 sw=4 et:
+-->

+ 1 - 13
documentation/manual/en/module_specs/Zend_Validate-Set.xml

@@ -149,19 +149,7 @@ if ($validator->isValid($iban)) {
 
     <xi:include href="Zend_Validate-Identical.xml" />
     <xi:include href="Zend_Validate-InArray.xml" />
-
-    <sect2 id="zend.validate.set.int">
-        <title>Int</title>
-
-        <para>
-            Returns <constant>TRUE</constant> if and only if <varname>$value</varname> is a valid
-            integer. Since Zend Framework 1.8 this validator takes into account the actual locale
-            from browser, environment or application wide set locale. You can of course use the
-            get/setLocale accessors to change the used locale or give it while creating a instance
-            of this validator.
-        </para>
-    </sect2>
-
+    <xi:include href="Zend_Validate-Int.xml" />
     <xi:include href="Zend_Validate-Ip.xml" />
     <xi:include href="Zend_Validate-Isbn.xml" />
     <xi:include href="Zend_Validate-LessThan.xml" />