JS簡單實現登陸驗證附效果圖_基礎知識

來源:互聯網
上載者:User
原始碼:
複製代碼 代碼如下:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<meta name="Author" content="劉江波">
<script type="text/javascript">
function login(){
var userName=document.getElementById("userName").value;
var pwd=document.getElementById("pwd").value;
var repwd=document.getElementById("repwd").value;
var address=document.getElementById("address").value;
var matchResult=true;
if(userName==""||pwd==""||repwd==""||address==""){
alert("請確認是否有空缺項!");
matchResult=false;
}else if(userName.length<6||userName.length>20){
alert("使用者名稱長度應在6到20個字元之間!");
matchResult=false;
}else if(userName==pwd||userName==repwd){
alert("密碼或重複密碼不能和使用者名稱相同!");
matchResult=false;
}else if(pwd.length<6||pwd.length>20||repwd.length<6||repwd.length>20){
alert("密碼或重複密碼長度應在6到20個字元之間!");
matchResult=false;
}else if(pwd!=repwd){
alert("密碼和重複密碼不同,請重新輸入!");
matchResult=false;
}else if(userName.length<6||userName.length>20){
alert("使用者名稱長度應在6到20個字元之間!");
matchResult=false;
}

if(matchResult==true){
var mailreg = /^\w+@\w+(\.\w+)+$/;
if(!address.match(mailreg)){
alert("郵箱格式不正確");
matchResult=false;
}
}


if(matchResult==true){
if(userName.charAt(0)>=0&&userName.charAt(0)<=9){
alert("使用者名稱不能以數字字元開始!");
matchResult=false;
}
}

return matchResult;
}
</script>
<title>使用者註冊及驗證</title>
</head>

<body>
<center>
<form name="loginForm" action="http://www.ytu.edu.cn" onsubmit="return login()" method="post">
<table bgcolor="#6666FF" width="300" cellspacing="0" cellpadding="0" border="0" align="left" valign="top">
<tr>
<td class="table-title" colspan="2" align="center" bgcolor="#3366FF">使用者註冊</td>
</tr>
<tr>
<td width="130" height="28" align="left">登入使用者名稱</td>
<td><input id="userName" name="userName" type="text" class="input"></td>
</tr>
<tr>
<td width="80" height="28" align="left">登入密碼</td>
<td><input id="pwd" name="pwd" type="password" class="input"></td>
</tr>
<tr>
<td width="80" height="28" align="left">重複輸入密碼</td>
<td><input id="repwd" name="repwd" type="password" class="input"></td>
</tr>
<tr>
<td width="80" height="28" align="left">有效郵箱地址</td>
<td><input id="address" name="address" type="text" class="input"></td>
</tr>
<tr>

<!--<td width="10" height="28" align="left"></td>-->
<td colspan="2">
<input type="submit" value="登入">
<input type="button" value="取消" onClick="reset()"></td>
</tr>
</table>
</form>
</center>

</body>
</html>

效果實現:

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.