⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 stringrangerule.class.php

📁 一个用PHP编写的
💻 PHP
字号:
<?php    lt_include( PLOG_CLASS_PATH."class/data/validator/rules/rule.class.php");    define( "ERROR_RULE_STRING_TOO_SMALL", "error_rule_string_too_small");    define( "ERROR_RULE_STRING_TOO_LARGE", "error_rule_string_too_large");    /**     * \ingroup Validator_Rules     *     * Given two values that will be used as lower and upper boundaries of the string length,      * validates if the length of the given string is between the limits.     *     * It will set the errors ERROR_RULE_STRING_TOO_SMALL or ERROR_RULE_STRING_TOO_LARGE in case the     * validation is not successful.     */    class StringRangeRule extends Rule    {        var $_minValue;        var $_maxValue;        /**         * Initializes the rule         *         * @param minValue the lower boundary of the range         * @param maxValue the upper boundary of the range         */        function StringRangeRule($minValue, $maxValue)        {            $this->Rule();            $this->_minValue = $minValue;            $this->_maxValue = $maxValue;        }        /**         * @return the lower boundary of the range         */        function getMinValue()        {            return $this->_minValue;        }        /**         * sets the lower boundary of the range         *         * @param minValue the minimum value         */        function setMinValue($minValue)        {            $this->_minValue = $minValue;        }        /**         * @return the upper boundary of the range         */        function getMaxValue()        {            return $this->_maxValue;        }        /**         * sets the lower boundary of the range         *         * @param minValue the minimum value         */        function setMaxValue($maxValue)        {            $this->_maxValue = $maxValue;        }        /**         * validates that the given value is within the two boundaries previously specified         *         * @param value The value to validate         * @return True if successful or false otherwise         */        function validate($value)        {            $len = strlen($value);            if ($len < $this->_minValue)            {                $this->_setError(ERROR_RULE_STRING_TOO_SMALL);                return false;            }            else if ($this->_maxValue != 0 && $len > $this->_maxValue)            {                $this->_setError(ERROR_RULE_STRING_TOO_LARGE);                return false;            }            else            {                $this->_setError(false);                return true;            }        }    }?>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -