现在的位置: 首页 > 综合 > 正文

手机号码验证的JS代码(包含153、159)

2012年12月29日 ⁄ 综合 ⁄ 共 1212字 ⁄ 字号 评论关闭
<script language="javascript" type="text/javascript">
<!--
function h()
{
document.mobileform.mobile.focus();
}

function checkMobile()
{
 
var mobile=document.mobileform.mobile.value;
 
var reg0=/^13\d{5,9}$/;   //130--139。至少7位
 var reg1=/^153\d{4,8}$/;  //联通153。至少7位
 var reg2=/^159\d{4,8}$/;  //移动159。至少7位
 var my=false;
 
if (reg0.test(mobile))my=true;
 
if (reg1.test(mobile))my=true;
 
if (reg2.test(mobile))my=true;
 
if (!my){
 document.mobileform.mobile.value
='';
 alert('对不起,您输入的手即号码错误。');
 document.mobileform.mobile.focus();}

 
return my;
}

//-->
</script>

 

<style type="text/css">
<!--
body,td,th 
{
 font-size
: 12px;
}

-->
</style>

 

<body onload=h()>
因为手机号码归属地查询只需要前7位就足够了,所以长度至少是7
<br>
要严格验证11位的话将{5,9}、{4,8}换成{8}即可!
<br><br>
<form action="http://www.j55.cn/mobile/index.asp" method="post" name="mobileform" target="_blank" id="mobileform" onsubmit="return checkMobile()">
            
<span style="color:#000000">手机号码:</span>       
            
<input name="mobile" type="text" id="mobile" size="20" maxlength="16" value="">
            
<input name="post" type="hidden" value="ok">
            
<input name="Submit" type="submit" class="style5" value="我要查询">
        
<input name="Submit2" type="reset" class="style5" value="重置">
    
</form>
</body>

抱歉!评论已关闭.