Просмотр исходного кода

[ZF-8978] Zend_Validate:

- added new section for Regex validator

git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@21501 44c647ce-9c0f-0410-b52a-842ac1e357ba
thomas 16 лет назад
Родитель
Сommit
94722a9365

+ 74 - 0
documentation/manual/en/module_specs/Zend_Validate-Regex.xml

@@ -0,0 +1,74 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- Reviewed: no -->
+<sect2 id="zend.validate.set.regex">
+    <title>Regex</title>
+
+    <para>
+        This validator allows you to validate if a given string conforms a defined regular
+        expression.
+    </para>
+
+    <sect3 id="zend.validate.set.regex.options">
+        <title>Supported options for Zend_Validate_Regex</title>
+
+        <para>
+            The following options are supported for <classname>Zend_Validate_Regex</classname>:
+        </para>
+
+        <itemizedlist>
+            <listitem>
+                <para>
+                    <emphasis><property>pattern</property></emphasis>: Sets the regular expression
+                    pattern for this validator.
+                </para>
+            </listitem>
+        </itemizedlist>
+    </sect3>
+
+    <sect3 id="zend.validate.set.regex.basic">
+        <title>Validation with Zend_Validate_Regex</title>
+
+        <para>
+            Validation with regular expressions allows to have complicated validations being done
+            without writing a own validator. The usage of regular expression is quite common and
+            simple. Let's look at some examples:
+        </para>
+
+        <programlisting language="php"><![CDATA[
+$validator = new Zend_Validate_Regex(array('pattern' => '/^Test/');
+
+$validator->isValid("Test"); // returns true
+$validator->isValid("Testing"); // returns true
+$validator->isValid("Pest"); // returns false
+]]></programlisting>
+
+        <para>
+            As you can see, the pattern has to be given using the same syntax as for
+            <methodname>preg_match</methodname>. For details about regular expressions take a look
+            into <link linkend="http://php.net/manual/en/reference.pcre.pattern.syntax.php">PHP's
+                manual about PCRE pattern syntax</link>.
+        </para>
+    </sect3>
+
+    <sect3 id="zend.validate.set.regex.handling">
+        <title>Pattern handling</title>
+
+        <para>
+            It is also possible to set a different pattern afterwards by using
+            <methodname>setPattern()</methodname> and to get the actual set pattern with
+            <methodname>getPattern()</methodname>.
+        </para>
+
+        <programlisting language="php"><![CDATA[
+$validator = new Zend_Validate_Regex(array('pattern' => '/^Test/');
+$validator->setPattern('ing$/');
+
+$validator->isValid("Test"); // returns false
+$validator->isValid("Testing"); // returns true
+$validator->isValid("Pest"); // returns false
+]]></programlisting>
+    </sect3>
+</sect2>
+<!--
+vim:se ts=4 sw=4 et:
+-->

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

@@ -167,16 +167,7 @@ if ($validator->isValid($iban)) {
     <xi:include href="Zend_Validate-LessThan.xml" />
     <xi:include href="Zend_Validate-NotEmpty.xml" />
     <xi:include href="Zend_Validate-PostCode.xml" />
-
-    <sect2 id="zend.validate.set.regex">
-        <title>Regex</title>
-
-        <para>
-            Returns <constant>TRUE</constant> if and only if <varname>$value</varname> matches
-            against a regular expression pattern.
-        </para>
-    </sect2>
-
+    <xi:include href="Zend_Validate-Regex.xml" />
     <xi:include href="Zend_Validate-Sitemap.xml" />
     <xi:include href="Zend_Validate-StringLength.xml" />
 </sect1>