php驗證手機號

1.實現代碼以下

        /**
	 * 	驗證手機號
	 * @param  [type] $tel [description]
	 * @return [type]      [description]
	 */
	function validatePhoneno($tel){
		//正則表達式 
		if(strlen($tel) == "11"){ 
			//上面部分判斷長度是否是11位 
			$n = preg_match_all("/13[123569]{1}\d{8}|15[1235689]\d{8}|188\d{8}/",
			$tel,$array); 
			/*接下來的正則表達式("/131,132,133,135,136,139開頭隨後跟着任意的8爲數字 '|
			'(或者的意思) 
			 * 151,152,153,156,158.159開頭的跟着任意的8爲數字 
			 * 或者是188開頭的再跟着任意的8爲數字,匹配其中的任意一組就經過了 
			 * /")*/
			if (empty($array)) {
				return false;
			}

			return true;
		}else{ 
		    return false;
		} 
	}

QQ截圖20181015150517.png

相關文章
相關標籤/搜索