nonemptyrule.class.php

来自「一个用PHP编写的」· PHP 代码 · 共 40 行

PHP
40
字号
<?php    lt_include(PLOG_CLASS_PATH."class/data/validator/rules/rule.class.php");    define( "ERROR_RULE_VALUE_IS_EMPTY", "error_rule_value_is_empty");    /**     * \ingroup Validator_Rules     *     * Validates if a string is empty or not     */    class NonEmptyRule extends Rule    {        /**         * Initializes the rule         */        function NonEmptyRule()        {            $this->Rule();        }        /**         * Returns true if the value is not empty or false otherwise. If empty,         * the error ERROR_RULE_VALUE_IS_EMPTY will be set.         *         * @param value the string that we'd like to validate         * @return true if successful or false otherwise         */        function validate($value)        {            if( $value == null || $value == "" || trim($value) == "" ) {                $this->_setError( ERROR_RULE_VALUE_IS_EMPTY );                return false;                        }            else {                return true;            }        }    }?>

⌨️ 快捷键说明

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