1: <?php
2:
3: /**
4: * This file contains the regular expression validator class.
5: *
6: * @package Core
7: * @subpackage Validation
8: * @author Murat Purc <murat@purc.de>
9: * @copyright four for business AG <www.4fb.de>
10: * @license http://www.contenido.org/license/LIZENZ.txt
11: * @link http://www.4fb.de
12: * @link http://www.contenido.org
13: */
14:
15: defined('CON_FRAMEWORK') || die('Illegal call: Missing framework initialization - request aborted.');
16:
17: /**
18: * Regular expression validation.
19: *
20: * Supports following options:
21: * <pre>
22: * - pattern (string) The regular expression pattern
23: * </pre>
24: *
25: * @package Core
26: * @subpackage Validation
27: */
28: class cValidatorRegex extends cValidatorAbstract {
29:
30: /**
31: *
32: * @see cValidatorAbstract::_isValid()
33: * @param mixed $value
34: * @return bool
35: */
36: protected function _isValid($value) {
37: if (!is_string($value)) {
38: $this->addError('Invalid value', 1);
39: return false;
40: } elseif (!$this->getOption('pattern')) {
41: $this->addError('Missing pattern', 2);
42: return false;
43: }
44:
45: $status = @preg_match($this->getOption('pattern'), $value);
46: if (false === $status) {
47: $this->addError('Pattern error', 3);
48: return false;
49: }
50:
51: if (!$status) {
52: $this->addError('No match', 4);
53: return false;
54: }
55:
56: return true;
57: }
58:
59: }
60: