Home  »  Code Snippets  »  Java Script  »

Validate Email using JavaScript

 Posted By : Manoj SahooPosted Date : 16/11/2010 01:38:48 PM Category : Java Script Points : 3

use below code to validate email by using javascript.

function validateEmail(email) {
   var pattern = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
   var address = document.getElementById(email).value;
   if(pattern.test(address) == false)

  {
      alert('Invalid Email Address');
     
   }
}

call the above method from any textbox's onblur event.

<asp:TextBox ID="txtEmail" runat="server" onblur="validateEmail('txtEmail');" Text=""></asp:TextBox>

Thank You.

Responses
No responses found for this thread. Be the first to respond this thread.
Post Reply
Login to post Response.