常用的正则表达试
public function funcStr($str,$num1='',$num2='') //字符正则表达试
{
if($num1!='' and $num2!=''){
return (preg_match("/^[a-zA-Z]{".$num1.",".$num2."}$/",$str))?true:false;
}else{
return (preg_match("/^[a-zA-Z]/",$str))?true:false;
}
}
public function funcNum($str,$num1='',$num2='')//数字正则表达试
{
if($num1!='' and $num2!=''){
return (preg_match("/^[0-9]{".$num1.",".$num2."}$/",$str))?true:false;
}else{
return (preg_match("/^[0-9]/",$str))?true:false;
}
}
public function funcCard($str)//
{
return (preg_match('/(^([d]{15}|[d]{18}|[d]{17}x)$)/',$str))?true:false;
}
public function funcEmail($str)//邮箱正则表达式
{
return (preg_match('/^[_.0-9a-z-A-Z-] @([0-9a-z][0-9a-z-] .) [a-z]{2,4}$/',$str))?true:false;
}
public function funcPhone($str)//电话号码正则表达试
{
return (preg_match("/^(((d{3}))|(d{3}-))?((0d{2,3})|0d{2,3}-)?[1-9]d{6,8}$/",$str))?true:false;
}
public function funcMtel($str)//手机号码正则表达试
{
return (preg_match("/(?:13d{1}|15[03689])d{8}$/",$str))?true:false;
}
public function funcZip($str)//邮编正则表达试
{
return (preg_match("/^[0-9]d{5}$/",$str))?true:false;
}
public function funcUrl($str)//url正则表达试
{
return (preg_match("/^http://[A-Za-z0-9] .[A-Za-z0-9] [/=?%-&_~`@[]': !]*([^<>""])*$/",$str))?true:false;
}
您可能感兴趣的文章:
常用的正则表达试
php正则表达式匹配中文的二个例子
正则表达式 模式匹配 Javascript
python如何使用正则表达式
Python re正则表达式模块及其用法
php正则ereg ereg_replace eregi eregi_replace split
通过实例学习php正则表达式之正则处理函数(preg_match,preg_match_all,preg_replace,preg_split)
正则表达式区配中文及日韩文字的方法分享
正则表达式使用详解
正则regex的posix标准,gnu扩展以及PC兼容性