Source for file WECRegex.class.php

Documentation is available at WECRegex.class.php

  1. <?php
  2. /**
  3. * @since Jul 23, 2005
  4. * @package polyphony.wizard.errorchecking
  5. *
  6. * @copyright Copyright &copy; 2005, Middlebury College
  7. * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License (GPL)
  8. *
  9. * @version $Id: WECRegex.class.php,v 1.7 2007/09/19 14:04:52 adamfranco Exp $
  10. */
  11. require_once(POLYPHONY."/main/library/Wizard/ErrorCheckingRules/WECRule.interface.php");
  12. /**
  13. * Allows for regular expression javascript error checking.
  14. *
  15. * @since Jul 23, 2005
  16. * @package polyphony.wizard.errorchecking
  17. *
  18. * @copyright Copyright &copy; 2005, Middlebury College
  19. * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License (GPL)
  20. *
  21. * @version $Id: WECRegex.class.php,v 1.7 2007/09/19 14:04:52 adamfranco Exp $
  22. */
  23. class WECRegex
  24. implements WECRule
  25. {
  26.  
  27. var $_regex;
  28. /**
  29. * Constructor
  30. * @param string $regex
  31. * @access public
  32. * @return void
  33. */
  34. function WECRegex ($regex) {
  35. $this->_regex = $regex;
  36. }
  37. /**
  38. * Returns a block of javascript code defining a function like so:
  39. *
  40. * function(element) {
  41. * return el.value.match(/\w+/);
  42. * }
  43. * @access public
  44. * @return string
  45. */
  46. function generateJavaScript () {
  47. $re = addslashes($this->_regex);
  48. return "function(el) {\n" .
  49. "var re = new RegExp(\"$re\");\n" .
  50. "return el.value.match(re);\n" .
  51. "}";
  52. }
  53. /**
  54. * Returns true if the passed {@link WizardComponent} validates against this rule.
  55. * @param ref object $component
  56. * @access public
  57. * @return boolean
  58. */
  59. function checkValue ($component) {
  60. $value = $component->getAllValues();
  61. if (preg_match("/".$this->_regex."/", $value)) return true;
  62. return false;
  63. }
  64. /**
  65. * gets the regular expression
  66. *
  67. * @access public
  68. * @return string the regular expression
  69. ***/
  70. function getRegularExpression() {
  71. return $this->_regex;
  72. }
  73. }
  74.  
  75.  
  76. ?>

Documentation generated on Wed, 19 Sep 2007 10:27:56 -0400 by phpDocumentor 1.3.0RC3