Validate email address using jQuery

Validate email address using jQuery

This is a very basic functionality to validate the email address. In this post, I will show you how to validate the email address using jQuery. To validate the email address, I have created a separate function which based on email address, returns true or false. Email address validation is done using regular expression.

function validateEmail(txtEmail){
   var a = document.getElementById(txtEmail).value;
   var filter = /^[a-zA-Z0-9_.-]+@[a-zA-Z0-9]+[a-zA-Z0-9.-]+[a-zA-Z0-9]+.[a-z]{1,4}$/;
    if(filter.test(a)){
        return true;
    }
    else{
        return false;
    }
}

One just need to make a call to this function to validate the email address. For demo, I have used on blur event of textbox. But It can be used on click on button or any another event.

$(document).ready(function() {
  $('#txtEmail').blur(function() {
      if(validateEmail('txtEmail'))
      {
          alert('Email is valid');
      }
      else
      {
          alert('Invalid Email Address');
      }
   });
});

Related Posts


5 thoughts on “Validate email address using jQuery

  1. Lida Buis

    I don’t even know the way I stopped up here, but I thought this submit was once good. I do not recognise who you are but certainly you are going to a well-known blogger for those who are not already πŸ˜‰ Cheers!

    Reply
  2. Denis Portela

    I just want to tell you that I am just newbie to weblog and certainly liked this blog site. Most likely I’m likely to bookmark your website . You certainly come with wonderful posts. Bless you for sharing your web-site.

    Reply
  3. Ms Office Mac 2011

    Wow! This can be one particular of the most beneficial blogs We’ve ever arrive across on this subject. Basically Great. I’m also an expert in this topic therefore I can understand your hard work.

    Reply
  4. Windows 7 Key

    I am not sure where you’re getting your info, but good topic. I needs to spend some time learning much more or understanding more. Thanks for wonderful information I was looking for this information for my mission.

    Reply
  5. Marco Winningham

    I just want to say I am all new to weblog and truly liked your page. Very likely I’m want to bookmark your blog . You certainly have beneficial stories. Thanks a bunch for revealing your website page.

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *


*