通過js正則驗(yàn)證手機(jī)號(hào)碼的有效性,方法如下:
驗(yàn)證130-139,150-159,180-189號(hào)碼段的手機(jī)號(hào)碼
<script type="text/javascript">
var myreg = /^(((13[0-9]{1})|(15[0-9]{1})|(18[0-9]{1}))+/d{8})$/;
if(!myreg.test($("#phone").val()))
{
alert('請輸入有效的手機(jī)號(hào)碼!');
return false;
}
</script>
以上代碼是在jquery下調(diào)試的。不需要jquery的代碼
function validatemobile(mobile)
{
if(mobile.length==0)
{
alert('請輸入手機(jī)號(hào)碼!');
document.form1.mobile.focus();
return false;
}
if(mobile.length!=11)
{
alert('請輸入有效的手機(jī)號(hào)碼!');
document.form1.mobile.focus();
return false;
}
var myreg = /^(((13[0-9]{1})|(15[0-9]{1})|(18[0-9]{1}))+/d{8})$/;
if(!myreg.test(mobile))
{
alert('請輸入有效的手機(jī)號(hào)碼!');
document.form1.mobile.focus();
return false;
}
}
本文轉(zhuǎn)自 361源碼網(wǎng) http://www.ke361.com/document/code/1589.html
|
新聞熱點(diǎn)
疑難解答
圖片精選