标签:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default3.aspx.cs" Inherits="Default3" %>
<!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 runat="server">
<title></title>
<script type="text/javascript" language="javascript">
var times = 60;
function FunCanUse() {
if ($("#Email").val() == "") {
$("#<%=this.Label1.ClientID %>").html("请输入邮箱");
}
else {
var t;
var partten = /^(\w)+(\.\w+)*@(\w)+((\.\w+)+)$/;
if (!partten.test(document.getElementById("Email").value)) {
return;
}
if (times == 60) {
var Email = $("#Email").val();
$.ajax({
type: "GET",
dataType: "json",
url: ‘<%=ResolveUrl("~")%>EmailRandCode.ashx‘,
data: "email=" + encodeURIComponent(Email) + "&action=delete&T=" + new Date(),
success: function (result) {
}
})
}
document.getElementById(‘btnSendCheckCode‘).style.display = "none";
times = times - 1;
document.getElementById(‘btnCode‘).style.display = "block";
document.getElementById(‘btnCode‘).value = times + "秒后重新获取";
t = setTimeout(‘FunCanUse()‘, 1000); //1秒后启用
if (times == 0) {
clearTimeout(t);
times = 60;
document.getElementById(‘btnSendCheckCode‘).value = ‘重新发送验证码‘;
document.getElementById(‘btnSendCheckCode‘).style.display = "block";
document.getElementById(‘btnCode‘).style.display = "none";
}
}
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<label class="lb">
<span class="required">*</span>邮箱</label>
<input id="Email" type="text" runat="server" class="ipt-t" tabindex="2" placeholder="请输入邮箱" />
<asp:Label ID="Label1" runat="server" Text="" ForeColor="Red"></asp:Label>
<a id="btnSendCheckCode" onclick="FunCanUse()" href="#" style="display: block; width: 80px;
margin-left: 280px; font-size: 12pt;">发送验证码</a>
<input id="btnCode" type="button" value="" style="width: 180px; margin-top: 5px;" />
</div>
</form>
</body>
</html>
aspx.sc 后台验证
页面验证(aspx页面)
if (Request.Cookies["EmailRandCode"] != null)
{
string strCheckCode = HttpUtility.UrlDecode(Request.Cookies["EmailRandCode"].Values[0].ToString());
string strCurDateTime = HttpUtility.UrlDecode(Request.Cookies["EmailRandCode"].Values[1].ToString());
//判断是否过期,若不过期,
DateTime dt = DateTime.Parse(strCurDateTime);
DateTime dtNow = System.DateTime.Now;
TimeSpan spT = dtNow - dt;
if (spT.TotalSeconds <= 180)
{
if (strCheckCode != txtCheckCode.Text.Trim())
{
this.AddResponseWriteScript("alert(‘验证码错误!‘);");
return;
}
}
else if (txtCheckCode.Text.Trim() == "")
{
this.AddResponseWriteScript("alert(‘请输入验证码!‘);");
return;
}
else
{
this.AddResponseWriteScript("alert(‘验证码过期,请重新获取!‘);");
return;
}
}
else if (txtCheckCode.Text.Trim() == "")
{
this.AddResponseWriteScript("alert(‘请输入验证码!‘);");
return;
}
else
{
this.AddResponseWriteScript("alert(‘验证码过期,请重新获取!‘);");
return;
}
标签:
原文地址:http://www.cnblogs.com/duanlinlin/p/5026084.html