Guest User

Untitled

a guest
Jul 11th, 2018
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 5 1.02 KB | None | 0 0
  1. <!doctype html>
  2. <html lang='en'>
  3.     <head>
  4.         <meta charset='utf-8'>
  5.         <title>email validator example</title>
  6.     </head>
  7.     <body>
  8.         <input type='text' id='email'/>
  9.         <p id='notice'></p>
  10.         <script type='text/javascript'>
  11.             (function() {
  12.                 var
  13.                     is_email=/^[\w\.%+-]+@[a-z0-9\.-]+\.[a-z]{2,4}$/i,
  14.                     email   =document.getElementById('email'),
  15.                     notice  =document.getElementById('notice');
  16.  
  17.                 function isValidEmail(txt) {
  18.                     return !!txt.match(is_email);
  19.                 }
  20.                 function updateAlert(e) {
  21.                     if(isValidEmail(email.value))
  22.                         notice.innerHTML='';
  23.                     else
  24.                         notice.innerHTML='Not a valid email address.';
  25.                 }
  26.  
  27.                 email.addEventListener('keyup',updateAlert);
  28.                 updateAlert();
  29.             })();
  30.         </script>
  31.     </body>
  32. </html>
Add Comment
Please, Sign In to add comment