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