Thursday, May 11, 2017

Validate Email in JavaScript

<!DOCTYPE html>
<html>
 <head>
  <title>Demo</title>
 </head>
<body>
 <h1>Validate Email in JavaScript</h1>
 <input type="text" id="email" />
 <button onclick="Validate()">Validate Email</button>
 <script>
  function Validate(){
   var mail = document.getElementById("email").value;
   alert(ValidateEmail(mail));
  }
function ValidateEmail(mail) {
    var re = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
    return re.test(mail);
} 
 </script>
</body>
</html>