Home php教程 php手册 php通用检测函数集合第1/3页

php通用检测函数集合第1/3页

Jun 13, 2016 pm 12:28 PM
php Revise function not yet Detection warn Universal gather

 
//【警告】:未经许可请勿随便修改 
//----------------------------------------------------------------------------------- 
------- 
//----------------------------------------------------------------------------------- 
------- 
// 
// 【文件名】: c_check.inc 
// 【作 用】: 通用检测函数集 
// 【作 者】: 天灰 
// 
// 【最后修改日期】: 2001/05/11[cxx] 
// 【变量定义规则】:‘C_'=字符型,‘I_'=整型,‘N_'=数字型,‘L_'=布尔型,‘A_'=数 
组型 
//----------------------------------------------------------------------------------- 
------- 
//----------------------------------------------------------------------------------- 
------- 
// ※CheckMoney($C_Money) 检查数据是否是 
99999.99格式 
// ※CheckEmailAddr($C_mailaddr) 判断是否为有效邮件地 
址 
// ※CheckWebAddr($C_weburl) 判断是否为有效网址 
// ※CheckEmpty($C_char) 判断字符串是否为空 
// ※CheckLengthBetween($C_char, $I_len1, $I_len2=100) 判断是否为指定长度内 
字符串 
// ※CheckUser($C_user) 判断是否为合法用户名 
// ※CheckPassword($C_passwd) 判断是否为合法用户密 
码 
// ※CheckTelephone($C_telephone) 判断是否为合法电话号 
码 
// ※CheckValueBetween($N_var, $N_val1, $N_val2) 判断是否是某一范围内的 
合法值 
// ※CheckPost($C_post) 判断是否为合法邮编(固 
定长度) 
// ※CheckExtendName($C_filename,$A_extend) 判断上传文件的扩展名 
// ※CheckImageSize($ImageFileName,$LimitSize) 检验上传图片的大小 
// ※AlertExit($C_alert,$I_goback=0) 非法操作警告并退出 
// ※Alert($C_alert,$I_goback=0) 非法操作警告 
// ※ReplaceSpacialChar($C_char) 特殊字符替换函数 
// ※ExchangeMoney($N_money) 资金转换函数 
// ※WindowLocation($C_url,$C_get="",$C_getOther="") PHP中的window.location 
函数 
//----------------------------------------------------------------------------------- 
------- 


//----------------------------------------------------------------------------------- 
------- 
// 函数名:CheckMoney($C_Money) 
// 作 用:检查数据是否是99999.99格式 
// 参 数:$C_Money(待检测的数字) 
// 返回值:布尔值 
// 备 注:无 
//----------------------------------------------------------------------------------- 
------- 
function CheckMoney($C_Money) 

if (!ereg("^[0-9][.][0-9]$", $C_Money)) return false; 
return true; 

//----------------------------------------------------------------------------------- 
------- 


//----------------------------------------------------------------------------------- 
------- 
// 函数名:CheckEmailAddr($C_mailaddr) 
// 作 用:判断是否为有效邮件地址 
// 参 数:$C_mailaddr(待检测的邮件地址) 
// 返回值:布尔值 
// 备 注:无 
//----------------------------------------------------------------------------------- 
------- 
function CheckEmailAddr($C_mailaddr) 

if (!eregi("^[_a-z0-9-]+(.[_a-z0-9-]+)*@[a-z0-9-]+(.[a-z0-9-]+)*$", 
$C_mailaddr)) 
//(!ereg("^[_a-zA-Z0-9-]+(.[_a-zA-Z0-9-]+)*@[_a-zA-Z0-9-]+(.[_a-zA-Z0-9-]+)*$", 
$c_mailaddr)) 

return false; 

return true; 

//----------------------------------------------------------------------------------- 
------- 


//----------------------------------------------------------------------------------- 
------- 
// 函数名:CheckWebAddr($C_weburl) 
// 作 用:判断是否为有效网址 
// 参 数:$C_weburl(待检测的网址) 
// 返回值:布尔值 
// 备 注:无 
//----------------------------------------------------------------------------------- 
------- 
function CheckWebAddr($C_weburl) 

if (!ereg("^http://[_a-zA-Z0-9-]+(.[_a-zA-Z0-9-]+)*$", $C_weburl)) 

return false; 

return true; 

//----------------------------------------------------------------------------------- 
------- 


//----------------------------------------------------------------------------------- 
------- 
// 函数名:CheckEmpty($C_char) 
// 作 用:判断字符串是否为空 
// 参 数:$C_char(待检测的字符串) 
// 返回值:布尔值 
// 备 注:无 
//----------------------------------------------------------------------------------- 
------- 
function CheckEmptyString($C_char) 

if (!is_string($C_char)) return false; //是否是字符串类型 
if (empty($C_char)) return false; //是否已设定 
if ($C_char=='') return false; //是否为空 
return true; 

//----------------------------------------------------------------------------------- 
------- 

//----------------------------------------------------------------------------------- 
------- 
// 函数名:CheckLengthBetween($C_char, $I_len1, $I_len2=100) 
// 作 用:判断是否为指定长度内字符串 
// 参 数:$C_char(待检测的字符串) 
// $I_len1 (目标字符串长度的下限) 
// $I_len2 (目标字符串长度的上限) 
// 返回值:布尔值 
// 备 注:无 
//----------------------------------------------------------------------------------- 
------- 
function CheckLengthBetween($C_cahr, $I_len1, $I_len2=100) 

$C_cahr = trim($C_cahr); 
if (strlen($C_cahr) if (strlen($C_cahr) > $I_len2) return false; 
return true; 

//----------------------------------------------------------------------------------- 
------- 

//----------------------------------------------------------------------------------- 
------- 
// 函数名:CheckUser($C_user) 
// 作 用:判断是否为合法用户名 
// 参 数:$C_user(待检测的用户名) 
// 返回值:布尔值 
// 备 注:无 
//----------------------------------------------------------------------------------- 
------- 
function CheckUser($C_user) 

if (!CheckLengthBetween($C_user, 4, 20)) return false; //宽度检验 
if (!ereg("^[_a-zA-Z0-9]*$", $C_user)) return false; //特殊字符检验 
return true; 

//----------------------------------------------------------------------------------- 
------- 

//----------------------------------------------------------------------------------- 
------- 
// 函数名:CheckPassword($C_passwd) 
// 作 用:判断是否为合法用户密码 
// 参 数:$C_passwd(待检测的密码) 
// 返回值:布尔值 
// 备 注:无 
//----------------------------------------------------------------------------------- 
------- 
function CheckPassword($C_passwd) 

if (!CheckLengthBetween($C_passwd, 4, 20)) return false; //宽度检测 
if (!ereg("^[_a-zA-Z0-9]*$", $C_passwd)) return false; //特殊字符检测 
return true; 

//----------------------------------------------------------------------------------- 
------- 

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot Article

Hot Article

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian Dec 24, 2024 pm 04:42 PM

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian

CakePHP Date and Time CakePHP Date and Time Sep 10, 2024 pm 05:27 PM

CakePHP Date and Time

CakePHP File upload CakePHP File upload Sep 10, 2024 pm 05:27 PM

CakePHP File upload

CakePHP Routing CakePHP Routing Sep 10, 2024 pm 05:25 PM

CakePHP Routing

Discuss CakePHP Discuss CakePHP Sep 10, 2024 pm 05:28 PM

Discuss CakePHP

CakePHP Project Configuration CakePHP Project Configuration Sep 10, 2024 pm 05:25 PM

CakePHP Project Configuration

CakePHP Quick Guide CakePHP Quick Guide Sep 10, 2024 pm 05:27 PM

CakePHP Quick Guide

How To Set Up Visual Studio Code (VS Code) for PHP Development How To Set Up Visual Studio Code (VS Code) for PHP Development Dec 20, 2024 am 11:31 AM

How To Set Up Visual Studio Code (VS Code) for PHP Development

See all articles