php常用正则表达式函数
这里面很多中正则表达式代码,包括有判断中文正则,数字字母正则,字符正则表达试,数字正则表达试,邮箱正则表达式,电话号码正则表达试,手机号码正则表达试,邮编正则表达试,/url正则表达试等,实例代码如下:
- function funcchinese($str,$num1='',$num2='')//判断中文正则
 - {
 - if($num1!='' and $num2!=''){
 - return (preg_match("/^([x81-xfe][x40-xfe]){".$num1.",".$num2."}$/",$str))?true:false;
 - }else{
 - return (!eregi("[^x80-xff]","$str"))?true:false;
 - }
 - }
 - function funcstrnum($str,$num1='',$num2='') //数字字母正则
 - {
 - if($num1!='' and $num2!=''){
 - return (preg_match("/^[^0-9a-za-z_@!.-]{".$num1.",".$num2."}$/",$str))?true:false;
 - }else{
 - return (preg_match("/^[^0-9a-za-z_@!.-]/",$str))?true:false;
 - }
 - }
 - // 常用的正则表达试
 - 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;
 - }
 - }
 - 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;
 - }
 - }
 - function funccard($str)//
 - {
 - return (preg_match('/(^([d]{15}|[d]{18}|[d]{17}x)$)/',$str))?true:false;
 - }
 - function funcemail($str)//邮箱正则表达式
 - {
 - return (preg_match('/^[_.0-9a-z-a-z-]+@([0-9a-z][0-9a-z-]+.)+[a-z]{2,4}$/',$str))?true:false;
 - }
 - function funcphone($str)//电话号码正则表达试
 - {
 - return (preg_match("/^(((d{3}))|(d{3}-))?((0d{2,3})|0d{2,3}-)?[1-9]d{6,8}$/",$str))?true:false;
 - }
 - function funcmtel($str)//手机号码正则表达试
 - {
 - return (preg_match("/(?:13d{1}|15[03689])d{8}$/",$str))?true:false;
 - }
 - function funczip($str)//邮编正则表达试
 - {//开源代码phpfensi.com
 - return (preg_match("/^[0-9]d{5}$/",$str))?true:false;
 - }
 - function funcurl($str)//url正则表达试
 - {
 - return (preg_match("/^http://[a-za-z0-9]+.[a-za-z0-9]+[/=?%-&_~`@[]':+!]*([^<>""])*$/",$str))?true:false;
 - }