Subversion Repositories Applications.papyrus

Rev

Rev 320 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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