E-mail Validation In JavaScript

  1. <script type="text/javascript">  
  2.     function validate_email(field, alerttxt) {  
  3.         with(field) {  
  4.             apos = value.indexOf("@");  
  5.             dotpos = value.lastIndexOf(".");  
  6.             if (apos < 1 || dotpos - apos < 2) {  
  7.                 alert(alerttxt);  
  8.                 return false;  
  9.             } else {  
  10.                 return true;  
  11.             }  
  12.         }  
  13.     }  
  14.   
  15.     function validate_form(thisform) {  
  16.         with(thisform) {  
  17.             if (validate_email(username, "Your UserName is Not Valid!") == false) {  
  18.                 username.focus();  
  19.                 return false;  
  20.             }  
  21.         }  
  22.     }  
  23. </script>