Source for file WECOptionalRegex.class.php

Documentation is available at WECOptionalRegex.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: WECOptionalRegex.class.php,v 1.3 2007/09/19 14:04:52 adamfranco Exp $
  10. */
  11. require_once(POLYPHONY."/main/library/Wizard/ErrorCheckingRules/WECRegex.class.php");
  12. /**
  13. * Allows for regular expression javascript error checking with optional values.
  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: WECOptionalRegex.class.php,v 1.3 2007/09/19 14:04:52 adamfranco Exp $
  22. */
  23. class WECOptionalRegex
  24. extends WECRegex
  25. {
  26. /**
  27. * Returns a block of javascript code defining a function like so:
  28. *
  29. * function(element) {
  30. * return el.value.match(/\w+/);
  31. * }
  32. * @access public
  33. * @return string
  34. */
  35. function generateJavaScript () {
  36. $re = addslashes($this->_regex);
  37. return "function(el) {\n" .
  38. "var re = new RegExp(\"$re\");\n" .
  39. "if (el.value == '')\n\t\t" .
  40. "return true;\n\t" .
  41. "else\n\t\t" .
  42. "return el.value.match(re);\n" .
  43. "}";
  44. }
  45. /**
  46. * Returns true if the passed {@link WizardComponent} validates against this rule.
  47. * @param ref object $component
  48. * @access public
  49. * @return boolean
  50. */
  51. function checkValue ($component) {
  52. $value = $component->getAllValues();
  53. if (!strval($value) == '')
  54. return true;
  55. else
  56. return parent::checkValue($component);
  57. }
  58. }
  59.  
  60.  
  61. ?>

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