1. 程式人生 > >javascript登錄檔單

javascript登錄檔單

html部分:
<html>
<head>
<title>登錄檔單</title>
<script language="JavaScript" src="check.js"></script>
</head>
<body>
<form name="form1"  onsubmit="return checkreg()" method="post" action="success.html"  >
  <table width="372" height="89" border="1" cellpadding="1" cellspacing="0" bordercolor="#0000FF" align="center">
    <tr>
      <td width="127" height="32">使用者名稱:</td>
      <td width="122"><label>
      <input type="text" name="username" id="User"/>
      </label>
    </tr>
    <tr>
      <td height="27">密碼:</td>
      <td height="27" colspan="2"><input type="password" name="pass" id="Pwd"></td>
    </tr>
    <tr>
      <td height="27">確認密碼:</td>
      <td height="27" colspan="2"><input type="password" name="passagain" id="Pwdagain"></td>
    </tr>
    <tr>
      <td height="27">QQ:</td>
      <td height="27" colspan="2"><input type="text" name="qq" id="Qq" onblur="Isval(Qq,'QQ')"></td>
    </tr>
    <tr>
      <td height="27">E-mail:</td>
      <td height="27" colspan="2"><input type="text" name="email" id="Email"></td>
    </tr><br><br><br>
	<tr>
	  <td colspan="2" align="center">
	  <input type="submit" name="Submit" value="提交" >    
	  <input type="reset" name="Reset" value="重置" /> 
	  </td>
	</tr> 
</table>
</form>
</body>
</html>
<html>
    <head>
	</head>
	<body>
	     <span>恭喜你,註冊成功。</span>
	</body>
</html>

JavaScript部分:

 function checkreg()
  {
	if (document.form1.User.value=="")
   {
    alert("請輸入您的手機號!");
    form1.User.focus();
    return false;
   }
    if (document.form1.User.value.length<11)
   {
    alert("手機號輸入不足十一位!");
    form1.User.focus();
    return false;
   }
    if (document.form1.User.value.length>11)
   {
    alert("手機號輸入超過十一位!");
    form1.User.focus();
    return false;
   }
    if (document.form1.Pwd.value=="")
   {
    alert("請輸入密碼!");
    form1.Pwd.focus();
    return false;
   }
    if (document.form1.Pwd.value.length<6 || document.form1.Pwd.value.length>15)
   {
    alert("密碼長度限制在6-15位!");
    form1.Pwd.focus();
    return false;
   }
   /*if (document.form1.Pwd.pattern!="[A-Za-z0-9]+{6,15}$")
   {
    alert("請輸入大寫字母!");
    form1.Pwd.focus();
    return false;
   }*/
    if(document.form1.Pwd.value!=document.form1.Pwdagain.value)
   {
    alert("兩次輸入的密碼不同!")
    form1.Pwd.focus();
    return false;
   }
    if (document.form1.Qq.value=="")
   {
    alert("請輸入您的QQ號碼!");
    form1.Qq.focus();
    return false;
   }
   if (document.form1.Qq.value.length>10 || document.form1.Qq.value.length<6)
   {
    alert("QQ長度應該在4-10位之間!");
    form1.Qq.focus();
    return false;
   }
    if (document.form1.Email.value=="")
   {
    alert("請輸入您的Email地址!");
    form1.Email.focus();
    return false;
   }
      var myRegex = /@.*\.[a-z]{2,6}/;
      var email = form1.Email.value;
      email = email.replace(/^ | $/g,"");
      email = email.replace(/^\.*|\.*$/g,"");
      email = email.toLowerCase();
       
    //驗證電子郵件的有效性
    if (email == "" || !myRegex.test(email))
    {
        alert ("請輸入有效的E-MAIL!");
        form1.Email.focus();
        return false;
    }
        return true;
  }
    function Isval(val,name)
    {
      if (val.value!='' && (isNaN(val.value) || val.value==0))
     {
      alert(name+"應填數字!");
       val.value="";
       val.focus();
     }
 }