小标
2018-09-14
来源 :
阅读 1188
评论 0
摘要:本文主要向大家介绍了PHP语言之PHP正则验证类,通过具体的内容向大家展示,希望对大家学习php语言有所帮助。
本文主要向大家介绍了PHP语言之PHP正则验证类,通过具体的内容向大家展示,希望对大家学习php语言有所帮助。
/**
*PHP正则验证类
*Code by T.T.R
*[url]//www.Gx3.cn[/url] [url]//Gx3.cn[/url]
*QQ:252319874
*/
class regExp
{
static function strTrim($str)
{
return preg_replace("/s/","",$str);
}
static function userName($str,$type,$len)
{
$str=self::strTrim($str);
if($len
{
return false;
}else{
switch($type)
{
case "EN"://纯英文
if(preg_match("/^[a-zA-Z]+$/",$str))
{
return true;
}else{
return false;
}
break;
case "ENNUM"://英文数字
if(preg_match("/^[a-zA-Z0-9]+$/",$str))
{
return true;
}else{
return false;
}
break;
case "ALL": //允许的符号(|-_字母数字)
if(preg_match("/^[|-_a-zA-Z0-9]+$/",$str))
{
return true;
}else{
return false;
}
break;
}
}
}
static function passWord($min,$max,$str)
{
$str=self::strTrim($str);
if(strlen($str)>=$min && strlen($str)<=$max)
{
return true;
}else{
return false;
}
}
static function Email($str)
{
$str=self::strTrim($str);
if(preg_match("/^([a-z0-9_]|\-|\.)+@(([a-z0-9_]|\-)+\.){1,2}[a-z]{2,4}$/i",$str))
{
return true;
}else{
return false;
}
}
static function idCard($str)
{
$str=self::strTrim($str);
if(preg_match("/^([0-9]{15}|[0-9]{17}[0-9a-z])$/i",$str))
{
return true;
}else{
return false;
}
}
static function Phone($type,$str)
{
$str=self::strTrim($str);
switch($type)
{
case "CHN":
if(preg_match("/^([0-9]{3}|0[0-9]{3})-[0-9]{7,8}$/",$str))
{
return true;
}else{
return false;
}
break;
case "INT":
if(preg_match("/^[0-9]{4}-([0-9]{3}|0[0-9]{3})-[0-9]{7,8}$/",$str))
{
return true;
}else{
return false;
}
break;
}
}
}
$str="008-010-2711204";
if(regExp::Phone("INT",$str))
{
echo "ok";
}else{
echo "no";
}
?>
本文由职坐标整理并发布,希望对同学们有所帮助。了解更多详情请关注职坐标编程语言PHP频道!
喜欢 | 1
不喜欢 | 0
您输入的评论内容中包含违禁敏感词
我知道了

请输入正确的手机号码
请输入正确的验证码
您今天的短信下发次数太多了,明天再试试吧!
我们会在第一时间安排职业规划师联系您!
您也可以联系我们的职业规划师咨询:
版权所有 职坐标-一站式AI+学习就业服务平台 沪ICP备13042190号-4
上海海同信息科技有限公司 Copyright ©2015 www.zhizuobiao.com,All Rights Reserved.
沪公网安备 31011502005948号