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