topical media & game development

talk show tell print

#javascript-code-04-email.js / js



  // A generic function for checking to see if an input element
  // looks like an email address
  function checkEmail( elem ) {
      // Make sure that something was entered and that it looks like
      // a valid email address
      return !elem.value || /^[a-z0-9_+.-]+\@([a-z0-9-]+\.)+[a-z0-9]{2,4}/i.test( elem.value );
  }
  
  // Get an input element to check
  var elem = document.getElementById("email");
  
  // Check to see if the field is valid, or not
  if ( ! checkEmail( elem ) ) {
      alert( "Field is not an email address." );
  }
  
  


(C) Æliens 20/2/2008

You may not copy or print any of this material without explicit permission of the author or the publisher. In case of other copyright issues, contact the author.