the-art-of-joomla-archive /redirect/code/trunk/administrator/components/com_redirect/libraries/jxtended/form/formrule.php

Language PHP Lines 71
MD5 Hash aea2761a5f7eaf622c2f365f0685803e Estimated Cost $515 (why?)
Repository https://bitbucket.org/eddieajau/the-art-of-joomla-archive View Raw File View Project SPDX
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<?php
/**
 * @version		$Id: formrule.php 390 2010-11-05 11:35:33Z eddieajau $
 * @package		JXtended.Libraries
 * @subpackage	Form
 * @copyright	Copyright 2005 - 2010 New Life in IT Pty Ltd. All rights reserved.
 * @license		GNU General Public License
 * @link		http://www.theartofjoomla.com
 */

defined('JPATH_BASE') or die;

// Detect if we have full UTF-8 and unicode support.
if (!defined('JFORM_UNICODE')) {
	define('JFORM_UNICODE', (bool)@preg_match('/\pL/u', 'a'));
}

/**
 * Form Rule class for JXtended Libraries.
 *
 * @package		JXtended.Libraries
 * @subpackage	Form
 * @since		1.1
 */
class JFormRule
{
	/**
	 * The regular expression.
	 *
	 * @var		string
	 */
	protected $_regex;

	/**
	 * The regular expression modifiers.
	 *
	 * @var		string
	 */
	protected $_modifiers;

	/**
	 * Method to test the value.
	 *
	 * @param	object		$field		A reference to the form field.
	 * @param	mixed		$values		The values to test for validiaty.
	 * @return	boolean		True if the value is valid, false otherwise.
	 * @throws	JException on invalid rule.
	 */
	public function test(&$field, &$values)
	{
		$return = false;
		$name	= $field->attributes('name');

		// Check for a valid regex.
		if (empty($this->_regex)) {
			throw new JException('Invalid Form Rule :: '.get_class($this));
		}

		// Add unicode support if available.
		if (JFORM_UNICODE) {
			$this->_modifiers = strpos($this->_modifiers, 'u') ? $this->_modifiers : $this->_modifiers.'u';
		}

		// Test the value against the regular expression.
		if (preg_match('#'.$this->_regex.'#'.$this->_modifiers, $values[$name])) {
			$return = true;
		}

		return $return;
	}
}
Back to Top