Validate email using JavaScript and Regular Expression not working in ASP.Net

Last Reply on Mar 19, 2014 05:56 AM By Mudassar

Posted on Mar 19, 2014 05:55 AM

hi all,
am new in javascript.
i have used to develop one application.
here i have make it used one validation process using java script.
i need to validate my email address.
if my email address is valid, i have redirect to another page.
if my email address is not valid, am getting invalid mail id.
but my problem is,
if my email address is valid, i can't able to redirect to another page. please find the code below
and let me know where am made mistake or else give me a valid code.
my code:


<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">

<html xmlns="" >
<head runat="server">
    <title>Untitled Page</title>
    <script type="text/javascript">
 function validEmail()

var mail = document.getElementById('email').value; // where `mail` is id of your input form
var email = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/;

  if (mail.match(email))
      alert("Invalid Email !!!");
		return false;
   return true;
    <form id="form1" name="form1" action="" method="post" runat="server">
    <input type="text" name="email" id="email">
        <asp:Button ID="Button1" runat="server" OnClientClick="return validEmail()" Text="Button" OnClick="Button1_Click" />

thanks in advance


Posted on Mar 19, 2014 05:56 AM


return true;


return false;