Email ID Validation using jQuery or Javascript

Introduction


This post shows how to validate an email ID in Javascript or jQuery. Here is a Javascript function to validate the email ID, you need to add the class "email" in the text control.
 
Code
  1. <script type="text/javascript">        
  2. $(document).ready(function () {        
  3.     
  4. $(".email").change(function () {    
  5. var inputvalues = $(this).val();    
  6. var regex = /^([a-zA-Z0-9_.+-])+\@(([a-zA-Z0-9-])+\.)+([a-zA-Z0-9]{2,4})+$/;    
  7. if(!regex.test(inputvalues)){    
  8. alert("invalid email id");    
  9. return regex.test(inputvalues);    
  10. }    
  11. });    
  12.     
  13.  });            
  14. </script>            
  15.           
  16. Html input type text          
  17. Email : <input type="text" class="email" >