日期:2014-05-16  浏览次数:20426 次

js判断手机号码归属地并是否有效
//手机归属地查询
	function searchMobileArea(){
	     var phone=$.trim($("#key_S").val());
	     if(searchAreaMobilePhoneFromIndex(phone)){//验证手机号
	         searchMobilePhoneGuiSuArea(phone);//查询手机归属地
	     }
	}
	
	//验证手机号
	function searchAreaMobilePhoneFromIndex(mobileNo){
	    if (mobileNo == "") {  alert("手机号不能为空"); return (false);  } 
        if (mobileNo.length != 11) { alert("请输入11位手机号"); return (false); }
		if (isNaN(mobileNo)){ alert("请输入11位数字"); return (false); }
        return true;
	}
	
	//查询手机归属地 
	function searchMobilePhoneGuiSuArea(mobileNo){
		 var $searchPhonearea = $("#searchPhoneArea");
	     $searchPhonearea.html("<div class='loadingdiv' style='width:150px;'><div class='loadingArea'>查询中,请稍候...</div></div>");
		 $.ajax({
	  		 type:"POST",
	  		 url:"https://service.sh.10086.cn/tools.do?method=getPhoneNativeInfo",
	  		 datatype:"text",
	  		 data:"phone="+mobileNo,
	  		 success:function(res){
	  		 	  var mobilehtml = "";
	  		      if(res!="-1" && res!="-2"){
					   mobilehtml += '<div>查询号码:<span class="fontHigh">'+mobileNo+'</span></div>';   
			           var result=res.split(";");
			           if(result[1]==result[3]){
					  	  mobilehtml += '<div>归属地为:<span class="fontHigh">'+result[1]+'</span></div>';   
			           } else {
					  	  mobilehtml += '<div>归属地为:<span class="fontHigh">'+result[1]+' '+result[3]+'</span></div>';
			           }
			           mobilehtml += '<div>区号为:<span class="fontHigh">0'+result[2]+'</span></div>';
			           $searchPhonearea.html( mobilehtml );
			           $("#key_S").val(""); 
		          } else { $searchPhonearea.html("<span class='fontHigh'>非常抱歉!系统中没有您需要的信息...</span>");	  }
	         },
	         error:function(xml){ $searchPhonearea.html("<span class='fontHigh'>非常抱歉!系统中没有您需要的信息...</span>");	 }
	     });
	}
	
	function searchMobileAreaBykeyDown(event,obj){
		var event=event||window.event;
		if(event.keyCode == 13){  searchMobileArea();  }
	}