Validator, captcha, form, #16
git-svn-id: svn+ssh://code.netmonsters.ru/svn/majestic/branches/evo@141 4cb57b5f-5bbd-dd11-951b-001d605cbbc5
This commit is contained in:
41
validator/RegexValidator.php
Normal file
41
validator/RegexValidator.php
Normal file
@ -0,0 +1,41 @@
|
||||
<?php
|
||||
/**
|
||||
* @copyright NetMonsters <team@netmonsters.ru>
|
||||
* @link http://netmonsters.ru
|
||||
* @package Majestic
|
||||
* @subpackage validator
|
||||
* @since 2010-04-26
|
||||
* @version SVN: $Id$
|
||||
* @filesource $URL$
|
||||
*/
|
||||
|
||||
class RegexValidator extends Validator
|
||||
{
|
||||
|
||||
const NOT_MATCH = 'regex_not_match';
|
||||
|
||||
protected $vars = array('regex');
|
||||
protected $templates = array(self::NOT_MATCH => '"%value%" does not match against regex "%regex%"');
|
||||
|
||||
protected $regex;
|
||||
|
||||
public function __construct($regex)
|
||||
{
|
||||
$this->regex = $regex;
|
||||
}
|
||||
|
||||
public function isValid($value, $context = null)
|
||||
{
|
||||
$this->setValue($value);
|
||||
|
||||
$status = preg_match($this->regex, $value);
|
||||
if ($status === false) {
|
||||
throw new Exception('Internal error matching regex "' . $this->regex . ' against value "' . $value . '"');
|
||||
}
|
||||
if (!$status) {
|
||||
$this->error();
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user