php 验证邮箱、url、数字程序代码
例子
<table width="620" align="center" border="0" cellpadding="1" cellspacing="1" style="background:#FB7"> <tr> <td width="464" height="27" bgcolor="#FFE7CE"> 代码如下</td> <td width="109" align="center" bgcolor="#FFE7CE" style="cursor:pointer;" onclick="doCopy('copy5486')">复制代码</td> </tr> <tr> <td height="auto" colspan="2" valign="top" bgcolor="#FFFFFF" style="padding:10px;" class="copyclass" id=copy5486>public static function isEmail( $email )
{
return preg_match("/^([a-z0-9]*[-_\.]?[a-z0-9] )*@([a-z0-9]*[-_]?[a-z0-9] ) [\.][a-z]{2,4}([\.][a-z]{2})?$/i" , $email );
}
public static function isNumber( $num )
{
return is_numeric( $num );
}
public static function isUrl( $url , $preg = false )
{
if( $preg )
{
$status = preg_match ( "/^([^:\/\/]) \:\/\/[\w-] \.[\w-.\?\/] $/" , $url );
}
else
{
$status = filter_var( $url , FILTER_VALIDATE_URL );
}
return $status;
}
补充:利用php自带函数来操作。
php验证邮箱
<table width="620" align="center" border="0" cellpadding="1" cellspacing="1" style="background:#FB7"> <tr> <td width="464" height="27" bgcolor="#FFE7CE"> 代码如下</td> <td width="109" align="center" bgcolor="#FFE7CE" style="cursor:pointer;" onclick="doCopy('copy3554')">复制代码</td> </tr> <tr> <td height="auto" colspan="2" valign="top" bgcolor="#FFFFFF" style="padding:10px;" class="copyclass" id=copy3554><?php
$email = 'fengdingbo@gmail.com';
$result = filter_var($email, FILTER_VALIDATE_EMAIL);
var_dump($result); // string(20) "fengdingbo@gmail.com"
php验证url地址
<table width="620" align="center" border="0" cellpadding="1" cellspacing="1" style="background:#FB7"> <tr> <td width="464" height="27" bgcolor="#FFE7CE"> 代码如下</td> <td width="109" align="center" bgcolor="#FFE7CE" style="cursor:pointer;" onclick="doCopy('copy2436')">复制代码</td> </tr> <tr> <td height="auto" colspan="2" valign="top" bgcolor="#FFFFFF" style="padding:10px;" class="copyclass" id=copy2436><?php
$url = "http://www.jiaochengji.com";
$result = filter_var($url, FILTER_VALIDATE_URL);
var_dump($result); // string(25) "http://www.jiaochengji.com"
php验证ip地址
<table width="620" align="center" border="0" cellpadding="1" cellspacing="1" style="background:#FB7"> <tr> <td width="464" height="27" bgcolor="#FFE7CE"> 代码如下</td> <td width="109" align="center" bgcolor="#FFE7CE" style="cursor:pointer;" onclick="doCopy('copy6402')">复制代码</td> </tr> <tr> <td height="auto" colspan="2" valign="top" bgcolor="#FFFFFF" style="padding:10px;" class="copyclass" id=copy6402><?php
$url = "192.168.1.110";
$result = filter_var($url, FILTER_VALIDATE_IP);
var_dump($result); // string(13) "192.168.1.110"
// 该方法也可以用来验证ipv6。
$url = "2001:DB8:2de::e13";
$result = filter_var($url, FILTER_VALIDATE_IP);
var_dump($result); // string(17) "2001:DB8:2de::e13"
您可能感兴趣的文章:
PHP、Mysql、jQuery找回密码的实现代码
jquery无刷新验证邮箱地址实现实例
PHP邮箱地址正确性验证示例
php 验证邮箱、url、数字程序代码
php正则验证邮箱的函数
php邮箱检测的正则表达式一例
PHP验证邮箱的正确与有效性(示例)
php中filter函数用法之验证邮箱、url和ip地址的方法
php邮件验证函数(示例)
PHP用户注册邮箱验证与激活帐号的示例代码