<?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 <ulink url="http://php.net/manual/en/reference.pcre.pattern.syntax.php">PHP's
                manual about PCRE pattern syntax</ulink>.
        </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:
-->
