码迷,mamicode.com
首页 > 移动开发 > 详细

手机号,邮箱,邮政编码的判断

时间:2018-04-18 11:44:45      阅读:223      评论:0      收藏:0      [点我收藏+]

标签:hex   array   cti   url   邮政编码   use   decode   turn   phone   

 

public function isEmail($str)
	{
		$j = "/^[\w|\.]+@\w+\.\w+/i";
		if(preg_match($j,$str))return $str;
		else return false;
	}

	public function isTelphone($str)
	{
		$j = "/^\d+-?\d+/i";
		if(preg_match($j,$str))return $str;
		else return false;
	}

	public function isZipCode($str)
	{
		$j = "/^\d{6}/i";
		if(preg_match($j,$str))return $str;
		else return false;
	}

	public function isUserName($str)
	{
		if(HE == ‘utf-8‘)
		{
			//if(eregi(‘^[\u0391-\uFFE5|\w]{2,40}$‘,$str))
			if(preg_match(‘/^[\x7f-\xff|\w]{2,40}$/i‘,$str))
			return $str;
			else return false;
		}
		else return true;
	}

	public function isAllowKey($str)
	{
		//$j = "/^[\w|\[|\]|\-|_]+$/i";
		$j = "/^[\w|\-|_]+$/i";
		if(preg_match($j,$str))return $str;
		else return false;
	}

	public function isPassword($str)
	{
		if(strlen($str)>=6)
		return $str;
		else return false;
	}

	public function isUrl($str)
	{
		$j = "/^http:\/\/.+/i";
		if(preg_match($j,$str))return $str;
		else return false;
	}

	public function subString($str,$lenth,$start = 0)
	{
		if(strlen($str) < $lenth && !$start)return $str;
		if(HE == ‘utf-8‘)$l = 3;
		else $l = 2;
		$k = 1;
		if($start)
		{
			$m = $start;
			while($k)if(ord($str[--$m]) < 128)$k = 0;
			$k = $l - ($lenth-$m)%$l;
			$start = $start + $k;
		}
		$t = substr($str,$start,$lenth);
		$m = $lenth;
		$k = 1;
		while($k)if(ord($t[--$m]) < 128)$k = 0;
		$k = ($lenth-1-$m)%$l;
		if($k)$t = substr($t,0,$lenth-$k);
		if($start)
		return $t;
		else
		return $t.‘...‘;
	}

	public function hexString($str,$hex = 16)
	{
		$tmp = "";
		$e = strlen($str);
		if(!$e)return false;
		for($i=0;$i<$e;$i++)
		{
			$t = base_convert(ord($str[$i]),10,16);
			$tmp .= "\x{$t}";
		}
		return $tmp;
	}

	public function encode($info)
	{
		$info = serialize($info);
		$key = CS;
		$kl = strlen($key);
		$il = strlen($info);
		for($i = 0; $i < $il; $i++)
		{
			$p = $i%$kl;
			$info[$i] = chr(ord($info[$i])+ord($key[$p]));
		}
		return urlencode($info);
	}

	public function decode($info)
	{
		$key = CS;
		$info = urldecode($info);
		$kl = strlen($key);
		$il = strlen($info);
		for($i = 0; $i < $il; $i++)
		{
			$p = $i%$kl;
			$info[$i] = chr(ord($info[$i])-ord($key[$p]));
		}
		$info = unserialize($info);
		return $info;
	}

	public function enstr($str)
	{
		$str = base64_encode($str);
		$str = str_replace(array(‘+‘,‘/‘,‘=‘),array(‘-‘,‘_‘,‘‘),$str);
		return $str;
	}

	public function destr($str)
	{
		$str = str_replace(array(‘-‘,‘_‘),array(‘+‘,‘/‘),$str);
		$str = base64_decode($str);
		return $str;
	}        

  

手机号,邮箱,邮政编码的判断

标签:hex   array   cti   url   邮政编码   use   decode   turn   phone   

原文地址:https://www.cnblogs.com/bluealine/p/8872521.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!