123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- <?php
- class HTML_QuickForm_Rule_Range extends HTML_QuickForm_Rule
- {
-
- public function validate($value, $options)
- {
- $length = api_strlen($value);
- switch ($this->name) {
- case 'min_numeric_length':
- return (float) $value >= $options;
- case 'max_numeric_length':
- return (float) $value <= $options;
- case 'minlength':
- return $length >= $options;
- case 'maxlength':
- return $length <= $options;
- default:
- return $length >= $options[0] && $length <= $options[1];
- }
- }
- public function getValidationScript($options = null)
- {
- switch ($this->name) {
- case 'minlength':
- $test = '{jsVar}.length < '.$options;
- break;
- case 'maxlength':
- $test = '{jsVar}.length > '.$options;
- break;
- default:
- $test = '({jsVar}.length < '.$options[0].' || {jsVar}.length > '.$options[1].')';
- }
- return array('', "{jsVar} != '' && {$test}");
- }
- }
|