/content/code/trunk/administrator/components/com_artofcontent/libraries/jxtended/form/formrule.php
PHP | 71 lines | 25 code | 9 blank | 37 comment | 4 complexity | feb44c05b78bfec7c3a5adb63288ebaa MD5 | raw file
- <?php
- /**
- * @version $Id: formrule.php 484 2010-12-20 23:40:27Z 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;
- }
- }