AJAX和WebService实现邮箱验证(无刷新验证邮件地址是否合法)
程序员文章站
2022-05-03 08:04:29
首先在项目里面添加服务引用 ---------------------------验证 email 地址是否正确.aspx----------------- 复制代码 代码...
首先在项目里面添加服务引用
---------------------------验证 email 地址是否正确.aspx-----------------
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<asp:scriptmanager id="scriptmanager1" runat="server">
</asp:scriptmanager>
<asp:updatepanel id="updatepanel1" runat="server">
<contenttemplate>
<div>
email<asp:textbox id="txtemail" runat="server"></asp:textbox><asp:label id="lblinfo"
runat="server" text=""></asp:label>
<br />
<br />
<asp:button id="button1" runat="server" text="调用" onclick="button1_click" />
</div>
</contenttemplate>
</asp:updatepanel>
</form>
</body>
</html>
--------------------验证 email 地址是否正确.aspx.cs-----------------------
protected void button1_click(object sender, eventargs e)
{
webemail.validateemailwebservice webemail = new webemail.validateemailwebservice();
byte result = webemail.validateemailaddress(txtemail.text);
if (result == 0)
{
lblinfo.text = "请重新验证";
}
else if (result == 1)
{
lblinfo.text = "邮件地址合法";
}
else if (result == 2)
{
lblinfo.text = "只是域名正确";
}
else if (result == 3)
{
lblinfo.text = "一个未知错误";
}
else if (result == 4)
{
lblinfo.text = "邮件服务器没有找到";
}
else if (result == 5)
{
lblinfo.text = "电子邮件地址错误";
}
else if (result == 6)
{
lblinfo.text = "免费用户验证超过数量(50次/24小时)";
}
else if (result == 7)
{
lblinfo.text = "商业用户不能通过验证";
}
}
---------------------------验证 email 地址是否正确.aspx-----------------
复制代码 代码如下:
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<asp:scriptmanager id="scriptmanager1" runat="server">
</asp:scriptmanager>
<asp:updatepanel id="updatepanel1" runat="server">
<contenttemplate>
<div>
email<asp:textbox id="txtemail" runat="server"></asp:textbox><asp:label id="lblinfo"
runat="server" text=""></asp:label>
<br />
<br />
<asp:button id="button1" runat="server" text="调用" onclick="button1_click" />
</div>
</contenttemplate>
</asp:updatepanel>
</form>
</body>
</html>
--------------------验证 email 地址是否正确.aspx.cs-----------------------
复制代码 代码如下:
protected void button1_click(object sender, eventargs e)
{
webemail.validateemailwebservice webemail = new webemail.validateemailwebservice();
byte result = webemail.validateemailaddress(txtemail.text);
if (result == 0)
{
lblinfo.text = "请重新验证";
}
else if (result == 1)
{
lblinfo.text = "邮件地址合法";
}
else if (result == 2)
{
lblinfo.text = "只是域名正确";
}
else if (result == 3)
{
lblinfo.text = "一个未知错误";
}
else if (result == 4)
{
lblinfo.text = "邮件服务器没有找到";
}
else if (result == 5)
{
lblinfo.text = "电子邮件地址错误";
}
else if (result == 6)
{
lblinfo.text = "免费用户验证超过数量(50次/24小时)";
}
else if (result == 7)
{
lblinfo.text = "商业用户不能通过验证";
}
}