关于原生js前端注册页面的相关验证

7 篇文章 0 订阅
6 篇文章 0 订阅
<!DOCTYPE html PUBLIC "-//W3C//Dtd XHTML 1.0 transitional//EN" "http://www.w3.org/tr/xhtml1/Dtd/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>验证注册页面</title>
<style  type="text/css">
body{lmargin:0;
     padding:0;}
.p1{font-size:12px;
   text-align:right; 
    height:28px;
    width:80px;
}
input{font-size:12px;
     border:solid 1px #61b16a ; 
    width:150px;
    height:20px;
}
.submit{
   font-size:12px;
   background-color:#eeeeee;
   border:solid 1px #cccccc ;
   width:60px;
   height:23px;
   padding-top:3px;
   }
textarea{
     font-size:12px;
      border:solid 1px #61b16a ;
     }
#mytable{
   margin-top: 0px;
   margin-right: auto;
   margin-bottom: 0px;
   margin-left: auto;
   width:760px;
   }
#main{border-left:solid 1px #7bcc87;
      border-right:solid 1px #7bcc87;
     background-color:#f9f8ff;
     }
#center{
      margin-top: 0px;
   margin-right: auto;
   margin-bottom: 0px;
   margin-left: auto;
   width:80%;
   }
</style>
<script type="text/javascript">
function checkname()
{
   var name=document.getElementById("username");
   document.getElementById("div").innerHTML="";
   if(name.value=="")
   {
      document.getElementById("div").innerHTML="名字不能为空";
      name.focus();
      return false;
      }
      for(var i=0;i<name.value.length;i++)
      {
         var char=name.value.substring(i,i+1);
         if(isNaN(char)==false)
         {
            document.getElementById("div").innerHTML="名字不能包含数字";
            name.select();
            return false;
            }
         }
         return true;
   }
   var pwd,pwd1
   function checkpwd()
   {
       pwd=document.getElementById("pwd")
       
      document.getElementById("div1").innerHTML="";
      
      if(pwd.value.length<=6)
      {
         document.getElementById("div1").innerHTML="密码必须等于或大于6个字符";
         pwd.focus();
         return false; 
         }
         return true;
         
      }
      function checkpwd1()
      {
         pwd1=document.getElementById("pwd1")
         document.getElementById("div2").innerHTML="";
         if(pwd.value!=pwd1.value)
         {
            document.getElementById("div2").innerHTML="两次输入的密码不一致";
            pwd1.select();
            return false;
            }
            return true;
         }
         
         function checkemail()
         {
            var email=document.getElementById("email");
               document.getElementById("div3").innerHTML="";
               if(email.value.indexOf("@")==-1||email.value.indexOf(".")==-1)
               {
         document.getElementById("div3").innerHTML="Email格式不正确,必须包含@和.";
         email.select()
         return false
                  }
                  return true
}
</script>
</head>

<body>
<table id="mytable" border="0" cellspacing="0" cellpadding="0">
  <form action="register.html" method="post" name="myform" οnsubmit="return (checkname()&&checkpwd()&&checkpwd1()&&checkemail())"><tr>
    <td><img src="images/reg-top.jpg"></td>
  </tr>
  <tr>
    <td id="main"><table id="center" border="0" cellspacing="0" cellpadding="0">
  <tr><td class="p1"> 用户名:</td>
    <td> <input id="username" type="text" οnblur="checkname()"><div id="div" style="color:#F00; display:inline">*</div></td>
  </tr>
  <tr><td class="p1"> &nbsp;&nbsp;码:</td>
    <td><input id="pwd" type="password" οnblur="checkpwd()"><div id="div1" style="color:#F00; display:inline">*</td>
  </tr>
   <tr><td class="p1" > 再次输入密码:</td>
    <td><input id="pwd1" type="password" οnblur="checkpwd1()"><div id="div2" style="color:#F00; display:inline">*</td>
  </tr>
  <tr><td class="p1" >E-mail:</td>
    <td><input id="email" type="text" οnblur="checkemail()"><div id="div3" style="color:#F00; display:inline">*</td>
  </tr>
  <tr><td class="p1"> 个人简介:</td>
    <td><textarea id="intro" cols="30" rows="4"></textarea></td>
  </tr>
</table>
</td>
  </tr>
  <tr>
    <td background="images/reg-end.jpg" style="height:63px; text-align:center;"><input name="B1" type="submit" value="提交" class="submit">&nbsp;&nbsp;
<input name="B2" type="reset" value="重置"class="submit">
    </td>
  </tr></form>
</table>
</body>
</html>
  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值