为什么有些文件夹的占用大小比它的实际大小要大- -| 回首页 | 2005年索引 | - -用上了Linux,没有X,我用elinks上网

一个简单的PHP Validator,100行以内哦!

                                      

发信人: hustoff (HUST Office), 信区: WebDev
标  题: 一个简单的PHP Validator,100行以内哦!
发信站: 武汉白云黄鹤站 (2005年05月14日16:57:30 星期六)

源文件下载:
http://byhh.net/cgi-bin/s/validator.php?n=validator.php&F=1116060990

class Validator
{
    public $errMsgs = array();

    public function Validate($queue)
    {
        $len = count($queue);
        for ($i = 0; $i < $len; $i ++)
        {
            $objVal = trim($queue[$i][0]);
            $func = $queue[$i][1];
            /*$validateCondition = $queue[$i][2];[optional]*/
            $allowNull = $queue[$i][3];
            $errMsg = $queue[$i][4];
            {
                if ($this->$func($queue[$i]) === false)
                {
                    $this->errMsgs[$i] = $errMsg;
                }
            }
        }
    }

    public function FitRegEx($obj)
    {
        $re = $obj[2];
        return !preg_match($re, $obj[0]) ? false : true;
    }

    public function AntiRegEx($obj)
    {
        $re = $obj[2];
        return preg_match($re, $obj[0]) ? false : true;
    }

    public function NotBlank($obj)
    {
        return empty($obj[0]) ? false : true;
    }

    public function IsNumeric($obj)
    {
        return !is_numeric($obj[0]) ? false : true;
    }

    public function IsInt($obj)
    {
        $re = '/^[1-9][0-9]+$/';
        return !preg_match($re, $obj[0]) ? false : true;
    }

    public function IsEmail($obj)
    {
        $re = '/^[a-zA-Z0-9_\.]+@([a-zA-Z0-9_-]+\.)+$/';
        $tempArr = explode(".",$obj[0]);
        $ext = $tempArr[count($tempArr)-1];
        $tempStr = str_replace($ext,'',$obj[0]);
        return (!preg_match($re,$tempStr) || !preg_match("/^[a-zA-Z]{2,4}$/",$ext) ? false : true;
    }

    public function IsPlainText($obj)
    {
        $re = '/<[a-zA-Z]+[^>]*>/';
        return preg_match($re, $obj[0]) ? false : true;
    }

    public function LengthRange($obj)
    {
        $vcMin = intval(substr($obj[2],0,strpos($obj[2],"to")));
        $vcMax = intval(substr($obj[2],strpos($obj[2],"to")+2));
        return (strlen($obj[0]) < $vcMin || strlen($obj[0]) > $vcMax) ? false : true;
    }

    public function NumericRange($obj)
    {
        $vcMin = intval(substr($obj[2],0,strpos($obj[2],"to")));
        $vcMax = intval(substr($obj[2],strpos($obj[2],"to")+2));
        return (!is_numeric($obj[0]) || $obj[0] < $vcMin || $obj[0] > $vcMax) ? false : true;
    }

    public function IsEqualTo($obj)
    {
        return $obj[0] != $obj[2] ? false : true;
    }

    public function CheckLimit($obj)
    {
        $vcMin = intval(substr($obj[2],0,strpos($obj[2],"to")));
        $vcMax = intval(substr($obj[2],strpos($obj[2],"to")+2)) == -1 ? count($obj[0]) : intval(substr($obj[2],strpos($obj[2],"to")+2));
        return (count($obj[0]) < $vcMin || count($obj[0]) > $vcMax) ? false : true;
    }
}
?>

【作者: 覃健祥】【访问统计:】【2005年08月1日 星期一 02:43】【 加入博采】【打印

Trackback

你可以使用这个链接引用该篇文章 http://publishblog.blogchina.com/blog/tb.b?diaryID=2447249

回复

验证码:   
评论内容: