PageRenderTime 48ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/content/code/trunk/administrator/components/com_artofcontent/libraries/jxtended/form/formrule.php

https://bitbucket.org/eddieajau/the-art-of-joomla-archive
PHP | 71 lines | 25 code | 9 blank | 37 comment | 4 complexity | feb44c05b78bfec7c3a5adb63288ebaa MD5 | raw file
  1. <?php
  2. /**
  3. * @version $Id: formrule.php 484 2010-12-20 23:40:27Z eddieajau $
  4. * @package JXtended.Libraries
  5. * @subpackage Form
  6. * @copyright Copyright 2005 - 2010 New Life in IT Pty Ltd. All rights reserved.
  7. * @license GNU General Public License
  8. * @link http://www.theartofjoomla.com
  9. */
  10. defined('JPATH_BASE') or die;
  11. // Detect if we have full UTF-8 and unicode support.
  12. if (!defined('JFORM_UNICODE')) {
  13. define('JFORM_UNICODE', (bool)@preg_match('/\pL/u', 'a'));
  14. }
  15. /**
  16. * Form Rule class for JXtended Libraries.
  17. *
  18. * @package JXtended.Libraries
  19. * @subpackage Form
  20. * @since 1.1
  21. */
  22. class JFormRule
  23. {
  24. /**
  25. * The regular expression.
  26. *
  27. * @var string
  28. */
  29. protected $_regex;
  30. /**
  31. * The regular expression modifiers.
  32. *
  33. * @var string
  34. */
  35. protected $_modifiers;
  36. /**
  37. * Method to test the value.
  38. *
  39. * @param object $field A reference to the form field.
  40. * @param mixed $values The values to test for validiaty.
  41. * @return boolean True if the value is valid, false otherwise.
  42. * @throws JException on invalid rule.
  43. */
  44. public function test(&$field, &$values)
  45. {
  46. $return = false;
  47. $name = $field->attributes('name');
  48. // Check for a valid regex.
  49. if (empty($this->_regex)) {
  50. throw new JException('Invalid Form Rule :: '.get_class($this));
  51. }
  52. // Add unicode support if available.
  53. if (JFORM_UNICODE) {
  54. $this->_modifiers = strpos($this->_modifiers, 'u') ? $this->_modifiers : $this->_modifiers.'u';
  55. }
  56. // Test the value against the regular expression.
  57. if (preg_match('#'.$this->_regex.'#'.$this->_modifiers, $values[$name])) {
  58. $return = true;
  59. }
  60. return $return;
  61. }
  62. }