1

Possible Duplicate:
Validate email address in Javascript?

I am just a beginner in jquery.I have used email field in my form. The form shouldn't submit if the email field is empty. I used the following code

if(document.getElementById('emailaddress').value == ''){
alert('Enter the Email Address');
document.getElementById('emailaddress').focus();
return false;
} 

How can i check the entered email is a valid one using simple jquery?

Community
  • 1
  • 1
designersvsoft
  • 1,861
  • 9
  • 39
  • 66

1 Answers1

0

Your best bet would be to use the jquery validate plugin.

A live email validation demo can be seen here

Here is some sample code:

<script src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.9/jquery.validate.js" type="text/javascript"></script>
<script>
$(function () {
   $("#myForm").validate({
    rules: {
      emailaddress : {
        required: true,
        email: true
      }
    }
   });
});
</script>
<form id="myForm">
Email address: <input type="text" name="emailaddress" id="emailaddress" class="required" >
</form>
Jake Feasel
  • 16,785
  • 5
  • 53
  • 66