您的位置:首页 > 其它

web常用方法总结

2016-04-27 17:25 204 查看
date_default_timezone_set('PRC');

header("Content-Type:text/html;charset=utf-8");

class funs {

   

   
校验电话号码,正则

    $telephone
电话号码 支持 010-12345678  01012345678两种

    $preg1 正则校验1
$preg2 正则校验2

    public
static function cktelephone($telephone){

  
   
 $preg1 =
"/^0[1-9][0-9]{1,2}-[1-9][0-9]{6,7}$/";

  
   
 $preg2 =
"/^0[1-9][0-9]{1,2}[1-9][0-9]{6,7}$/";

  
   
 $rt1 = preg_match($preg1,$telephone);

  
   
 $rt2 = preg_match($preg2,$telephone);

  
   
 if($rt1||$rt2){

  
   
   
 return true;

  
   
 }

  
   
 return false;

    }

    校验手机号码

    支持手机类型
13,14,15,18

    public
static function ckmobile($mobile){

  
   
 $preg = "/^1[3|4|5|8][0-9]{9}$/";

  
   
 if(preg_match($preg,$mobile)){

  
   
   
 return true;

  
   
 }

  
   
 return false;

    }

    邮箱正则处理

   
支持长度最大为4-80

    public
static function ckemail($email){

  
   
 $preg="/^[a-zA-Z1-9_\.-][a-zA-Z0-9_.-]{3,32}@([a-zA-Z0-9_]+\.){1,5}[A-Za-z]{2,4}$/";

  
   
 if( preg_match($preg,$email)
&& strlen($email)<70
){

  
   
   
 return true;  
 

  
   
 }

  
   
 return false;

    }

   
密码复杂度校验处理

    public
static function ckpwd($password){

  
   
 $ErrorArr = array(

  
   
   
 "请勿使用纯字母",

  
   
   
 "请勿使用纯数字",

  
   
   
 "请勿使用连续字符",

  
   
   
 "请勿使用空格",

  
   
   
 "密码长度建议为6-20个字符,支持字母、数字、下划线、点"

  
   
 );

  
   
 if(preg_match("/^[a-zA-Z]+$/",$password)){

  
   
   
 return $ErrorArr[0];

  
   
 } else
if(preg_match("/^[0-9]+$/",$password)){

  
   
  
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: