PageRenderTime 41ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 0ms

/campsite/src/include/pear/HTML/QuickForm/Rule/Range.php

https://github.com/joechrysler/Campsite
PHP | 75 lines | 29 code | 6 blank | 40 comment | 5 complexity | ec8b9cd04565f00f97001b974cfc900f MD5 | raw file
Possible License(s): BSD-3-Clause, AGPL-1.0, LGPL-2.1, Apache-2.0
  1. <?php
  2. /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
  3. /**
  4. * Checks that the length of value is within range
  5. *
  6. * PHP versions 4 and 5
  7. *
  8. * LICENSE: This source file is subject to version 3.01 of the PHP license
  9. * that is available through the world-wide-web at the following URI:
  10. * http://www.php.net/license/3_01.txt If you did not receive a copy of
  11. * the PHP License and are unable to obtain it through the web, please
  12. * send a note to license@php.net so we can mail you a copy immediately.
  13. *
  14. * @category HTML
  15. * @package HTML_QuickForm
  16. * @author Bertrand Mansion <bmansion@mamasam.com>
  17. * @copyright 2001-2009 The PHP Group
  18. * @license http://www.php.net/license/3_01.txt PHP License 3.01
  19. * @version CVS: $Id: Range.php,v 1.8 2009/04/04 21:34:04 avb Exp $
  20. * @link http://pear.php.net/package/HTML_QuickForm
  21. */
  22. /**
  23. * Abstract base class for QuickForm validation rules
  24. */
  25. require_once 'HTML/QuickForm/Rule.php';
  26. /**
  27. * Checks that the length of value is within range
  28. *
  29. * @category HTML
  30. * @package HTML_QuickForm
  31. * @author Bertrand Mansion <bmansion@mamasam.com>
  32. * @version Release: 3.2.11
  33. * @since 3.2
  34. */
  35. class HTML_QuickForm_Rule_Range extends HTML_QuickForm_Rule
  36. {
  37. /**
  38. * Validates a value using a range comparison
  39. *
  40. * @param string $value Value to be checked
  41. * @param mixed $options Int for length, array for range
  42. * @access public
  43. * @return boolean true if value is valid
  44. */
  45. function validate($value, $options)
  46. {
  47. $length = strlen($value);
  48. switch ($this->name) {
  49. case 'minlength': return ($length >= $options);
  50. case 'maxlength': return ($length <= $options);
  51. default: return ($length >= $options[0] && $length <= $options[1]);
  52. }
  53. } // end func validate
  54. function getValidationScript($options = null)
  55. {
  56. switch ($this->name) {
  57. case 'minlength':
  58. $test = '{jsVar}.length < '.$options;
  59. break;
  60. case 'maxlength':
  61. $test = '{jsVar}.length > '.$options;
  62. break;
  63. default:
  64. $test = '({jsVar}.length < '.$options[0].' || {jsVar}.length > '.$options[1].')';
  65. }
  66. return array('', "{jsVar} != '' && {$test}");
  67. } // end func getValidationScript
  68. } // end class HTML_QuickForm_Rule_Range
  69. ?>