`
cherryQQ
  • 浏览: 1127123 次
  • 性别: Icon_minigender_1
  • 来自: 厦门
社区版块
存档分类
最新评论

js 电话号码验证

阅读更多
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>javascript基础表单验证测试页面</title>
<script language="javascript">
function check(){
var uid = document.forms[0].Id.value;
var uname = document.forms[0].Name.value;
var uage = document.forms[0].Age.value;
var usex = document.forms[0].Sex.value;
var reg=/^([0-9]|[\-])+$/g ;

if(""==uid){
alert("编号不能为空!");
document.forms[0].Id.focus();
return false;
}

if(!reg.test(uid)){
   alert("请输入有效的电话!例如:13572136666或者029-82316227");
         return false;

       }


if(uid.length<7 || uid.length>18){
   alert("the phone must be between 7 and 18!");
        return false;
       }

if(""==uname){
alert("请输入姓名!");
document.forms[0].Name.focus();
return false;
}
if(""==uage){
alert("请输入年龄!");
document.forms[0].Age.focus();
return false;
}
if(""==usex){
alert("请输入性别!");
document.forms[0].Sex.focus();
return false;
}

}

function isTel(){

   var reg=/^([0-9]|[\-])+$/g ;
       if(uid.length<7 || uid.length>18){
        return false;
       }
       else{
         return reg.exec(uid);
       }



}


function btnesc(){
document.forms[0].Id.value="";
document.forms[0].Name.value="";
document.forms[0].Age.value="";
document.forms[0].Sex.value="";

}
</script>

</head>
<body bgcolor="">
<center><form action="*.do" method="post">
<h4>
js测试表单:
</h4>
<table border="0" cellspacing="1" cellpadding="1">
<caption>表格标题--用户注册表单验证测试</caption>
<tr>
<td width="10%"bgcolor="#6495ed">
编号
</td>
<td bgcolor="#6495ed">
姓名
</td>
<td bgcolor="#6495ed">
年龄
</td>
<td bgcolor="#6495ed">
性别
</td>
</tr>

<tr>
<td bgcolor="#c0c0c0">
<input type="text" name="id" id="Id">
</td>
<td bgcolor="#c0c0c0">
<input type="text" name="name" id="Name">
</td>
<td bgcolor="#c0c0c0">
<input type="text" name="age" id="Age">
</td>
<td bgcolor="#c0c0c0">
<input type="text" name="sex" id="Sex">
</td>
</tr>
</table>
<input type="button" name="btn" onclick="check();" value="确认">&nbsp;<input type="button" name="" onclick="btnesc();" value="重置">
</form>
</center>
</body>
</html>
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics