Development

/branches/1.1/lib/validator/sfValidatorRegex.class.php

You must first sign up to be able to contribute.

root/branches/1.1/lib/validator/sfValidatorRegex.class.php

Revision 9048, 1.2 kB (checked in by FabianLange, 7 years ago)

1.1: fixed @param phpdoc to fit specs in validator (refs #2991)

  • Property svn:mime-type set to text/x-php
  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
Line 
1 <?php
2
3 /*
4  * This file is part of the symfony package.
5  * (c) Fabien Potencier <fabien.potencier@symfony-project.com>
6  *
7  * For the full copyright and license information, please view the LICENSE
8  * file that was distributed with this source code.
9  */
10
11 /**
12  * sfValidatorRegex validates a value with a regular expression.
13  *
14  * @package    symfony
15  * @subpackage validator
16  * @author     Fabien Potencier <fabien.potencier@symfony-project.com>
17  * @version    SVN: $Id$
18  */
19 class sfValidatorRegex extends sfValidatorBase
20 {
21   /**
22    * Configures the current validator.
23    *
24    * Available options:
25    *
26    *  * pattern: A regex pattern compatible with PCRE (required)
27    *
28    * @param array $options   An array of options
29    * @param array $messages  An array of error messages
30    *
31    * @see sfValidatorBase
32    */
33   protected function configure($options = array(), $messages = array())
34   {
35     $this->addRequiredOption('pattern');
36   }
37
38   /**
39    * @see sfValidatorBase
40    */
41   protected function doClean($value)
42   {
43     $clean = (string) $value;
44
45     if (!preg_match($this->getOption('pattern'), $clean))
46     {
47       throw new sfValidatorError($this, 'invalid', array('value' => $value));
48     }
49
50     return $clean;
51   }
52 }
53
Note: See TracBrowser for help on using the browser.