HTML_QuickForm
[ class tree: HTML_QuickForm ] [ index: HTML_QuickForm ] [ all elements ]

Source for file Range.php

Documentation is available at Range.php

  1. <?php
  2. /* vim: set expandtab tabstop=4 shiftwidth=4: */
  3. // +----------------------------------------------------------------------+
  4. // | PHP version 4.0                                                      |
  5. // +----------------------------------------------------------------------+
  6. // | Copyright (c) 1997-2003 The PHP Group                                |
  7. // +----------------------------------------------------------------------+
  8. // | This source file is subject to version 2.0 of the PHP license,       |
  9. // | that is bundled with this package in the file LICENSE, and is        |
  10. // | available at through the world-wide-web at                           |
  11. // | http://www.php.net/license/2_02.txt.                                 |
  12. // | If you did not receive a copy of the PHP license and are unable to   |
  13. // | obtain it through the world-wide-web, please send a note to          |
  14. // | license@php.net so we can mail you a copy immediately.               |
  15. // +----------------------------------------------------------------------+
  16. // | Authors: Bertrand Mansion <bmansion@mamasam.com>                     |
  17. // +----------------------------------------------------------------------+
  18. //
  19. // $Id: Range.php,v 1.6 2003/11/03 16:08:24 avb Exp $
  20.  
  21. require_once('HTML/QuickForm/Rule.php');
  22.  
  23. /**
  24. * Validates values using range comparison
  25. @version     1.0
  26. */
  27. {
  28.     /**
  29.      * Validates a value using a range comparison
  30.      *
  31.      * @param     string    $value      Value to be checked
  32.      * @param     mixed     $options    Int for length, array for range
  33.      * @access    public
  34.      * @return    boolean   true if value is valid
  35.      */
  36.     function validate($value$options)
  37.     {
  38.         $length strlen($value);
  39.         switch ($this->name{
  40.             case 'minlength'return ($length >= $options);
  41.             case 'maxlength'return ($length <= $options);
  42.             default:          return ($length >= $options[0&& $length <= $options[1]);
  43.         }
  44.     // end func validate
  45.  
  46.  
  47.     function getValidationScript($options = null)
  48.     {
  49.         switch ($this->name{
  50.             case 'minlength'
  51.                 $test '{jsVar}.length < '.$options;
  52.                 break;
  53.             case 'maxlength'
  54.                 $test '{jsVar}.length > '.$options;
  55.                 break;
  56.             default: 
  57.                 $test '({jsVar}.length < '.$options[0].' || {jsVar}.length > '.$options[1].')';
  58.         }
  59.         return array(''"{jsVar} != '' && {$test}");
  60.     // end func getValidationScript
  61.  
  62. // end class HTML_QuickForm_Rule_Range
  63. ?>

Documentation generated on Mon, 11 Mar 2019 14:16:36 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.