1 <?xml version="1.0" encoding="UTF-8"?>
3 <sect2 id="zend.validate.set.regex">
7 This validator allows you to validate if a given string conforms a defined regular
11 <sect3 id="zend.validate.set.regex.options">
12 <title>Supported options for Zend_Validate_Regex</title>
15 The following options are supported for <classname>Zend_Validate_Regex</classname>:
21 <emphasis><property>pattern</property></emphasis>: Sets the regular expression
22 pattern for this validator.
28 <sect3 id="zend.validate.set.regex.basic">
29 <title>Validation with Zend_Validate_Regex</title>
32 Validation with regular expressions allows to have complicated validations being done
33 without writing a own validator. The usage of regular expression is quite common and
34 simple. Let's look at some examples:
37 <programlisting language="php"><![CDATA[
38 $validator = new Zend_Validate_Regex(array('pattern' => '/^Test/');
40 $validator->isValid("Test"); // returns true
41 $validator->isValid("Testing"); // returns true
42 $validator->isValid("Pest"); // returns false
46 As you can see, the pattern has to be given using the same syntax as for
47 <methodname>preg_match</methodname>. For details about regular expressions take a look
48 into <ulink url="http://php.net/manual/en/reference.pcre.pattern.syntax.php">PHP's
49 manual about PCRE pattern syntax</ulink>.
53 <sect3 id="zend.validate.set.regex.handling">
54 <title>Pattern handling</title>
57 It is also possible to set a different pattern afterwards by using
58 <methodname>setPattern()</methodname> and to get the actual set pattern with
59 <methodname>getPattern()</methodname>.
62 <programlisting language="php"><![CDATA[
63 $validator = new Zend_Validate_Regex(array('pattern' => '/^Test/');
64 $validator->setPattern('ing$/');
66 $validator->isValid("Test"); // returns false
67 $validator->isValid("Testing"); // returns true
68 $validator->isValid("Pest"); // returns false