Tuesday 7 January 2020

Email id validation using jquery or javascript

Introduction

Here is a javascript function to validate email id.
you need to add class "email" in 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" >  

No comments:

Post a Comment