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
|
<?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:
-->
|