|
Moodle
2.2.1
http://www.collinsharper.com
|
00001 <?php 00002 /* vim: set expandtab tabstop=4 shiftwidth=4: */ 00003 // +----------------------------------------------------------------------+ 00004 // | PHP version 4.0 | 00005 // +----------------------------------------------------------------------+ 00006 // | Copyright (c) 1997-2003 The PHP Group | 00007 // +----------------------------------------------------------------------+ 00008 // | This source file is subject to version 2.0 of the PHP license, | 00009 // | that is bundled with this package in the file LICENSE, and is | 00010 // | available at through the world-wide-web at | 00011 // | http://www.php.net/license/2_02.txt. | 00012 // | If you did not receive a copy of the PHP license and are unable to | 00013 // | obtain it through the world-wide-web, please send a note to | 00014 // | license@php.net so we can mail you a copy immediately. | 00015 // +----------------------------------------------------------------------+ 00016 // | Authors: Bertrand Mansion <bmansion@mamasam.com> | 00017 // +----------------------------------------------------------------------+ 00018 // 00019 // $Id: Range.php,v 1.2 2010/12/14 17:35:59 moodlerobot Exp $ 00020 00021 require_once('HTML/QuickForm/Rule.php'); 00022 00027 class HTML_QuickForm_Rule_Range extends HTML_QuickForm_Rule 00028 { 00037 function validate($value, $options) 00038 { 00039 $length = strlen($value); 00040 switch ($this->name) { 00041 case 'minlength': return ($length >= $options); 00042 case 'maxlength': return ($length <= $options); 00043 default: return ($length >= $options[0] && $length <= $options[1]); 00044 } 00045 } // end func validate 00046 00047 00048 function getValidationScript($options = null) 00049 { 00050 switch ($this->name) { 00051 case 'minlength': 00052 $test = '{jsVar}.length < '.$options; 00053 break; 00054 case 'maxlength': 00055 $test = '{jsVar}.length > '.$options; 00056 break; 00057 default: 00058 $test = '({jsVar}.length < '.$options[0].' || {jsVar}.length > '.$options[1].')'; 00059 } 00060 return array('', "{jsVar} != '' && {$test}"); 00061 } // end func getValidationScript 00062 00063 } // end class HTML_QuickForm_Rule_Range 00064 ?>