DIV CSS 佈局教程網

 DIV+CSS佈局教程網 >> 網頁腳本 >> JavaScript入門知識 >> JavaScript基礎知識 >> JS簡單實現登陸驗證附效果圖
JS簡單實現登陸驗證附效果圖
編輯:JavaScript基礎知識     
源代碼:
復制代碼 代碼如下:
<!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>

效果實現:
XML學習教程| jQuery入門知識| AJAX入門| Dreamweaver教程| Fireworks入門知識| SEO技巧| SEO優化集錦|
Copyright © DIV+CSS佈局教程網 All Rights Reserved