adding some strings
[moodle-linuxchix.git] / lib / pear / HTML / QuickForm / Rule / Range.php
blob6f83a8eefa7cfdb3ed2a4132bb2015c59cc14048
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 // +----------------------------------------------------------------------+
19 // $Id$
21 require_once('HTML/QuickForm/Rule.php');
23 /**
24 * Validates values using range comparison
25 * @version 1.0
27 class HTML_QuickForm_Rule_Range extends HTML_QuickForm_Rule
29 /**
30 * Validates a value using a range comparison
32 * @param string $value Value to be checked
33 * @param mixed $options Int for length, array for range
34 * @access public
35 * @return boolean true if value is valid
37 function validate($value, $options)
39 $length = strlen($value);
40 switch ($this->name) {
41 case 'minlength': return ($length >= $options);
42 case 'maxlength': return ($length <= $options);
43 default: return ($length >= $options[0] && $length <= $options[1]);
45 } // end func validate
48 function getValidationScript($options = null)
50 switch ($this->name) {
51 case 'minlength':
52 $test = '{jsVar}.length < '.$options;
53 break;
54 case 'maxlength':
55 $test = '{jsVar}.length > '.$options;
56 break;
57 default:
58 $test = '({jsVar}.length < '.$options[0].' || {jsVar}.length > '.$options[1].')';
60 return array('', "{jsVar} != '' && {$test}");
61 } // end func getValidationScript
63 } // end class HTML_QuickForm_Rule_Range