用于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">
<title>无标题文档</title>
<script language="javascript">
function hao()
{
//用户名验证
var n=document.myform.textname.value;
if(n.length==0)
{
alert("用户名不能为空");
return false;
}
//密码验证
var p=document.myform.textpass.value;
var s=document.myform.textpass1.value;
if(p.length==0)
{
alert("密码不能为空");
return false;
}
if(s.length==0)
{
alert("重设密码不能为空");
return false;
}
if(p.length<6||s.length<6)
{
alert("密码长度不能小于6位");
return false;
}
if(s!=p)
{
alert("重设密码必须与密码一至");
return false;
}
//出生日期验证
var a1=document.myform.text1.value;
var a2=document.myform.text2.value;
var a3=document.myform.text3.value;
if(a1.length==0||a2.length==0||a3.length==0)
{
alert("您的出生年月日不能为空!");
}
if(isNaN(a1)||isNaN(a2)||isNaN(a3))
{
alert("您的出生年月日必须是数字");
return false;
}
if(a2<1||a2>12)
{
alert("您的出生月份填写错误!!");
return false;
}
if(a3<1||a3>31)
{
alert("您的出生日填写错误!!");
return false;
}
//电子邮箱验证
var e=document.myform.textemail.value;
if(e.length==0)
{
alert("电子邮箱不能为空");
return false;
}
if(e.indexOf("@",0)==-1)
{
alert("电子邮箱必须包含@符号!!");
return false;
}
if(e.indexOf(".",0)==-1)
{
alert("电子邮箱必须包含.符号!!");
return false;
}
//复选框
var ch=document.myform.checkbox.checked;
if(!ch)
{
alert("您必须同意我们的协议和政策!!")
return false;
}else
{
alert("注册成功!!");
}
return true;
}
//选中复先框 按钮的变化
function hh()
{
var c=document.myform.checkbox.checked;
if(c==true)
{
document.myform.Submit1.disabled=false;
}else
{
document.myform.Submit1.disabled=true;
}
}
//打开会员协议
function hy()
{
window.open("hy.html");
}
</script>
<style type="text/css">
<!--
.style1 {color: #FF0000}
-->
</style>
</head>
<body>
<form name="myform" method="post" action="" onSubmit=" return hao()">
<table width="480" border="0" align="center">
<tr>
<td colspan="2"><div align="center">用户信息注册</div></td>
</tr>
<tr>
<td width="150">用户名:</td>
<td width="320"><input type="text" name="textname"></td>
</tr>
<tr>
<td>密码:</td>
<td><input type="password" name="textpass"></td>
</tr>
<tr>
<td>再次输入密码:</td>
<td><input type="password" name="textpass1"></td>
</tr>
<tr>
<td>性别:</td>
<td><input type="radio" name="radiobutton" value="radiobutton">
<input type="radio" name="radiobutton" value="radiobutton">
</td>
</tr>
<tr>
<td>出生日期:</td>
<td><input name="text1" type="text" size="10">
<input name="text2" type="text" size="6">
<input name="text3" type="text" size="6">
</td>
</tr>
<tr>
<td>电子邮箱:</td>
<td><input type="text" name="textemail"></td>
</tr>
<tr>
<td colspan="2"><p align="center">
<input type="checkbox" name="checkbox" value="checkbox" onClick="hh()">
我同意遵守<A href="javascript:hy()" class="style1" >会员协议</A></p>
</td>
</tr>
<tr>
<td><div align="right">
<input type="submit" name="Submit1" value="注册" disabled>
</div></td>
<td><div><input type="reset" name="Submit2" value="重填">
</div></td>
</tr>
</table>
<p>&nbsp;</p>
<p>&nbsp;</p>
</form>
</body>
</html>
    
    
<!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">
<title>无标题文档</title>
<script language="javascript">
function hao()
{
//用户名验证
var n=document.myform.textname.value;
if(n.length==0)
{
alert("用户名不能为空");
return false;
}
//密码验证
var p=document.myform.textpass.value;
var s=document.myform.textpass1.value;
if(p.length==0)
{
alert("密码不能为空");
return false;
}
if(s.length==0)
{
alert("重设密码不能为空");
return false;
}
if(p.length<6||s.length<6)
{
alert("密码长度不能小于6位");
return false;
}
if(s!=p)
{
alert("重设密码必须与密码一至");
return false;
}
//出生日期验证
var a1=document.myform.text1.value;
var a2=document.myform.text2.value;
var a3=document.myform.text3.value;
if(a1.length==0||a2.length==0||a3.length==0)
{
alert("您的出生年月日不能为空!");
}
if(isNaN(a1)||isNaN(a2)||isNaN(a3))
{
alert("您的出生年月日必须是数字");
return false;
}
if(a2<1||a2>12)
{
alert("您的出生月份填写错误!!");
return false;
}
if(a3<1||a3>31)
{
alert("您的出生日填写错误!!");
return false;
}
//电子邮箱验证
var e=document.myform.textemail.value;
if(e.length==0)
{
alert("电子邮箱不能为空");
return false;
}
if(e.indexOf("@",0)==-1)
{
alert("电子邮箱必须包含@符号!!");
return false;
}
if(e.indexOf(".",0)==-1)
{
alert("电子邮箱必须包含.符号!!");
return false;
}
//复选框
var ch=document.myform.checkbox.checked;
if(!ch)
{
alert("您必须同意我们的协议和政策!!")
return false;
}else
{
alert("注册成功!!");
}
return true;
}
//选中复先框 按钮的变化
function hh()
{
var c=document.myform.checkbox.checked;
if(c==true)
{
document.myform.Submit1.disabled=false;
}else
{
document.myform.Submit1.disabled=true;
}
}
//打开会员协议
function hy()
{
window.open("hy.html");
}
</script>
<style type="text/css">
<!--
.style1 {color: #FF0000}
-->
</style>
</head>
<body>
<form name="myform" method="post" action="" onSubmit=" return hao()">
<table width="480" border="0" align="center">
<tr>
<td colspan="2"><div align="center">用户信息注册</div></td>
</tr>
<tr>
<td width="150">用户名:</td>
<td width="320"><input type="text" name="textname"></td>
</tr>
<tr>
<td>密码:</td>
<td><input type="password" name="textpass"></td>
</tr>
<tr>
<td>再次输入密码:</td>
<td><input type="password" name="textpass1"></td>
</tr>
<tr>
<td>性别:</td>
<td><input type="radio" name="radiobutton" value="radiobutton">
<input type="radio" name="radiobutton" value="radiobutton">
</td>
</tr>
<tr>
<td>出生日期:</td>
<td><input name="text1" type="text" size="10">
<input name="text2" type="text" size="6">
<input name="text3" type="text" size="6">
</td>
</tr>
<tr>
<td>电子邮箱:</td>
<td><input type="text" name="textemail"></td>
</tr>
<tr>
<td colspan="2"><p align="center">
<input type="checkbox" name="checkbox" value="checkbox" onClick="hh()">
我同意遵守<A href="javascript:hy()" class="style1" >会员协议</A></p>
</td>
</tr>
<tr>
<td><div align="right">
<input type="submit" name="Submit1" value="注册" disabled>
</div></td>
<td><div><input type="reset" name="Submit2" value="重填">
</div></td>
</tr>
</table>
<p>&nbsp;</p>
<p>&nbsp;</p>
</form>
</body>
</html>
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值