Home > Backend Development > PHP Tutorial > PHP verify mobile phone number (supports location query and encoding as UTF8)_PHP tutorial

PHP verify mobile phone number (supports location query and encoding as UTF8)_PHP tutorial

WBOY
Release: 2016-07-21 15:13:27
Original
1198 people have browsed it

Copy code The code is as follows:

//Mobile phone number verification
function checkMobileValidity($mobilephone) {
$exp = "/^13[0-9]{1}[0-9]{8}$|15[012356789]{1}[0-9]{8}$|18[012356789] {1}[0-9]{8}$|14[57]{1}[0-9]$/";
if(preg_match($exp,$mobilephone)){
return true;
}else{
return false;
}
}
//Mobile phone number location (return: such as Guangdong Mobile)
function checkMobilePlace($mobilephone){
$ url = "http://tcc.taobao.com/cc/json/mobile_tel_segment.htm?tel=".$mobilephone."&t=".time();
$content = file_get_contents($url);
$p = substr($content, 56, 4);
$mo = substr($content, 81, 4);
return $str = conv2utf8($p).conv2utf8($mo);
}
// Convert string encoding to UTF8
function conv2utf8($text){
return mb_convert_encoding($text,'UTF-8','ASCII,GB2312,GB18030,GBK,UTF -8');
}

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/326501.htmlTechArticleCopy the code as follows: ?php // Mobile phone number verification function checkMobileValidity($mobilephone){ $exp = "/ ^13[0-9]{1}[0-9]{8}$|15[012356789]{1}[0-9]{8}$|18[012356789]{1}[0-9]{ 8}$|14[...
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