Home > Article > Backend Development > Verify mobile phone number and location with PHP_PHP Tutorial
A practical PHP function code, regular expression to verify the correctness of the mobile phone number and query the location of the mobile phone number. Let’s look at the specific code of this function:
view sourceprint?01
02//Mobile phone number verification
03function checkMobileValidity($mobilephone){
04$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]$/";
05if(preg_match($exp,$mobilephone)){
06return true;
07}else{
08return false;
09}
10}
11//Mobile phone number location
12function checkMobilePlace($mobilephone){
13$url = "http://tcc.taobao.com/cc/json/mobile_tel_segment.htm?tel=".$mobilephone."&t=".time();
14$content = file_get_contents($url);
15$p = substr($content, 56, 4);
16$mo = substr($content, 81, 4);
17return $str = conv2utf8($p).conv2utf8($mo);
18}
19?>
Querying the mobile phone location is to call Taobao’s mobile phone location resources. Please pay attention to the address of this page. If it fails, you can find the correct address on Taobao.