JS驗證手機號碼格式
其實對于驗證手機號碼,網上的例子很多,可是由于153(聯通)、159(移動)等新區段的開通,使很多的驗證修改起來比較麻煩。所以今天呈上一個容易修改的JavaScript的驗證。
function validatemobile(mobile)
{
if(mobile.length==0)
{
alert('請輸入手機號碼!');
document.form1.mobile.focus();
return false;
}
if(mobile.length!=11)
{
alert('請輸入有效的手機號碼!');
document.form1.mobile.focus();
return false;
}
var myreg = /^(((13[0-9]{1})|159|153)+\d{8})$/;
if(!myreg.test(mobile))
{
alert('請輸入有效的手機號碼!');
document.form1.mobile.focus();
return false;
}
}</pre>
本文由用戶 y37f 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!