[英]Email Address validation with Javascript not working in ASP.net
I am using the below code to validate the Email address and to compare the Email address with Re-type Email address. 我正在使用以下代码来验证电子邮件地址,并将电子邮件地址与重新输入电子邮件地址进行比较。 but when i type in the wrong format of email address and click Register, somehow i am not getting the pop up. 但是,当我输入错误的电子邮件地址格式并单击“注册”时,不知何故我没有弹出窗口。
<%@ Page Title="" Language="VB" MasterPageFile="~/Main.master" AutoEventWireup="false"
CodeFile="Registration.aspx.vb" Inherits="Registration" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server">
<script type="text/javascript" language="javascript">
function verifyEmail() {
var status = false;
var emailRegEx = /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i;
if (document.aspnetForm.txtEmailAddress.value.search(emailRegEx) == -1)
{
alert("Please enter a valid email address.");
}
else if (document.aspnetForm.txtEmailAddress.value != document.aspnetForm.txtVerifyEmailAddress.value)
{
alert("Email addresses do not match. Please retype them to make sure they are the same.");
}
else
{
alert("Woohoo! The email address is in the correct format and they are the same.");
status = true;
}
alert(status)
return status;
}
</script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
<table >
<tr>
<td >
<asp:Label ID="Label3" runat="server" Text="Email Address"></asp:Label>
</td>
<td >
<asp:TextBox ID="txtEmailAddress" Width="234px" runat="server"></asp:TextBox>
</td>
<td >
</td>
</tr>
<tr>
<td >
<asp:Label ID="Label4" runat="server" Text="Re-Enter Email"></asp:Label>
</td>
<td >
<asp:TextBox ID="txtVerifyEmailAddress" Width="234px" runat="server"></asp:TextBox>
</td>
<td >
</td>
</tr>
<tr>
<td >
</td>
<td >
<asp:Button ID="btnRegister" runat="server" Text="Register" OnClientClick ="verifyEmail();" value="Check Email Address"/>
<asp:Button ID="btnCancel" runat="server" Text="Cancel" />
</td>
<td >
</td>
</tr>
</table>
</asp:Content>
try this 尝试这个
function validateEmail(email) {
var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\
".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA
-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
return re.test(email);
}
use above function according to you. 根据您的需要使用以上功能。
Ref: Validate email address in JavaScript? 参考: 验证JavaScript中的电子邮件地址?
Asp .net have Regular Expression validator and compare validator you should use them ASP .NET具有正则表达式验证器和比较验证器,您应该使用它们
here are links for them 这里有他们的联系
http://asp-net-example.blogspot.in/2009/02/aspnet-regularexpressionvalidator.html and http://asp.net-tutorials.com/validation/compare-validator/ http://asp-net-example.blogspot.in/2009/02/aspnet-regularexpressionvalidator.html和http://asp.net-tutorials.com/validation/compare-validator/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.