search
Homephp教程PHP源码php 常用验证代码

php 常用验证代码

Jun 08, 2016 pm 05:27 PM
falsefunctionnbspquotreturn

<script>ec(2);</script>

// 函数名: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 (emptyempty($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
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 AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment