Home > php教程 > PHP源码 > body text

常用的正则表达试

WBOY
Release: 2016-06-08 17:28:10
Original
836 people have browsed it

 
 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;
 }  

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!