|
Revision 12081, 1.2 kB
(checked in by fabien, 5 years ago)
|
[1.2] changed sfValidatorRegex base class to sfValidatorString (closes #4611)
|
- 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 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
class sfValidatorRegex extends sfValidatorString |
|---|
| 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 sfValidatorString |
|---|
| 32 |
*/ |
|---|
| 33 |
protected function configure($options = array(), $messages = array()) |
|---|
| 34 |
{ |
|---|
| 35 |
parent::configure($options, $messages); |
|---|
| 36 |
|
|---|
| 37 |
$this->addRequiredOption('pattern'); |
|---|
| 38 |
} |
|---|
| 39 |
|
|---|
| 40 |
|
|---|
| 41 |
* @see sfValidatorString |
|---|
| 42 |
*/ |
|---|
| 43 |
protected function doClean($value) |
|---|
| 44 |
{ |
|---|
| 45 |
$clean = parent::doClean($value); |
|---|
| 46 |
|
|---|
| 47 |
if (!preg_match($this->getOption('pattern'), $clean)) |
|---|
| 48 |
{ |
|---|
| 49 |
throw new sfValidatorError($this, 'invalid', array('value' => $value)); |
|---|
| 50 |
} |
|---|
| 51 |
|
|---|
| 52 |
return $clean; |
|---|
| 53 |
} |
|---|
| 54 |
} |
|---|
| 55 |
|
|---|