【php开源代码栏目提醒】:本文主要为网学会员提供Validation.class.php,希望对需要Validation.class.php网友有所帮助,学习一下!
<?php
// +----------------------------------------------------------------------
// | Think
PHP // +----------------------------------------------------------------------
// | Copyright (c) 2008 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: liu21st <liu21st@gmail.com>
// +----------------------------------------------------------------------
// $Id$
/**
+------------------------------------------------------------------------------
* 鏁版嵁楠岃瘉绫?
+------------------------------------------------------------------------------
* @category ORG
* @package ORG
* @subpackage Text
* @author liu21st <liu21st@gmail.com>
* @version $Id$
+------------------------------------------------------------------------------
*/
class Validation extends Base
{//绫诲畾涔夊紑濮?
/**
+----------------------------------------------------------
* 棰勫畾涔夐獙璇佹牸寮?
+----------------------------------------------------------
* @var integer
* @access protected
+----------------------------------------------------------
*/
static $regex = array(
'require'=> '/.+/', //鍖归厤浠绘剰瀛楃锛岄櫎浜嗙┖鍜屾柇琛岀
'email' => '/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/',
'phone' => '/^((\(\d{2,3}\))|(\d{3}\-))?(\(0\d{2,3}\)|0\d{2,3}-)?[1-9]\d{6,7}(\-\d{1,4})?$/',
'mobile' => '/^((\(\d{2,3}\))|(\d{3}\-))?(13|15)\d{9}$/',
'url' => '/^http:\/\/[A-Za-z0-9]+\.[A-Za-z0-9]+[\/=\?%\-&_~`@[\]\':+!]*([^<>\"\"])*$/',
'currency' => '/^\d+(\.\d+)?$/',
'number' => '/\d+$/',
'zip' => '/^[1-9]\d{5}$/',
'qq' => '/^[1-9]\d{4,12}$/',
'integer' => '/^[-\+]?\d+$/',
'double' => '/^[-\+]?\d+(\.\d+)?$/',
'english' => '/^[A-Za-z]+$/',
);
/**
+----------------------------------------------------------
* 楠岃瘉鏁版嵁椤?
+----------------------------------------------------------
* @access public
+----------------------------------------------------------
* @param string $checkName 楠岃瘉鐨勬暟鎹被鍨嬪悕鎴栨鍒欏紡
* @param string $value 瑕侀獙璇佺殑鏁版嵁
+----------------------------------------------------------
* @return boolean
+----------------------------------------------------------
* @throws ThinkExecption
+----------------------------------------------------------
*/
static function check($value,$checkName)
{
$matchRegex = self::getRegex($checkName);
return preg_match($matchRegex,trim($value));
}
/**
+----------------------------------------------------------
* 鍙栧緱楠岃瘉绫诲瀷鐨勬鍒欒〃杈惧紡
+----------------------------------------------------------
* @access public
+----------------------------------------------------------
* @param string $name 楠岃瘉绫诲瀷鍚嶇О
+----------------------------------------------------------
* @return string
+----------------------------------------------------------
* @throws ThinkExecption
+----------------------------------------------------------
*/
static function getRegex($name)
{
if(isset(self::$regex[strtolower($name)])) {
return self::$regex[strtolower($name)];
}else {
return $name;
}
}
}//绫诲畾涔夌粨鏉?
?>