轉自(http://caibaojian.com/regexp-example.html)
js代碼
function checkPhone(){
var phone = document.getElementById('phone').value;
if(!(/^1[34578]\d{9}$/.test(phone))){
alert("手機號碼有誤,請重填");
return false;
}
}
或者用以下js代碼
function checkPhone(){
var phone = document.getElementById('phone').value;
if(!(/^1(3|4|5|7|8)\d{9}$/.test(phone))){
alert("手機號碼有誤完箩,請重填");
return false;
}
}