用JS检查电话号码是否正确
2015-04-22来源:易贤网

规则:只能入数字和()-+四个字符

<!--

function check()

{

if (document.form.tell.value==""){

alert("请输入电话!");

document.form.tell.focus();

return false;

}

else{

var Letters = "0123456789()+-";

for (i=0; i< document.form.tell.value.length; i++){

var CheckChar = document.form.tell.value.charAt(i);

if (Letters.indexOf(CheckChar) == -1){

alert("電話號碼格式不正確!");

document.form.tell.focus();

return false;

}

}

}

}

//-->

</script>

在<body>...</body>之间的表单加入下面代码: <form method="POST" name=form action="">

<p align="center">

请输入电话号码:<input type="text" name="tell" size="20">

<input type="submit" value="提交" name="B1"></p>

</form>

更多信息请查看IT技术专栏

2025公考·省考培训课程试听预约报名

  • 报班类型
  • 姓名
  • 手机号
  • 验证码
推荐信息