function emailCheck (emailStr)
{
   // The following variable tells the rest of the function whether or not
   // to verify that the address ends in a two-letter country or well-known
   // TLD.  1 means check it, 0 means don't.
   var checkTLD = 1;


   // The following string represents the pattern for matching all special
   // characters.  We don't want to allow special characters in the address.
   // These characters include ( ) < > @ , ; : \ " . [ ]
   var specialChars = "\\(\\)><@,;:\\\\\\\"\\.\\[\\]";

   // The following string represents the range of characters allowed in a
   // username or domainname.  It really states which chars aren't allowed.
   var validChars = "\[^\\s" + specialChars + "\]";

   // The following pattern applies if the "user" is a quoted string (in
   // which case, there are no rules about which characters are allowed
   // and which aren't; anything goes).  E.g. "jiminy cricket"@disney.com
   // is a legal e-mail address.
   var quotedUser = "(\"[^\"]*\")";

   // The following string represents an atom (basically a series of non-special characters.)
   var atom = validChars + '+';

   // The following string represents one word in the typical username.
   // For example, in john.doe@somewhere.com, john and doe are words.
   // Basically, a word is either an atom or quoted string.
   var word = "(" + atom + "|" + quotedUser + ")";

   // The following pattern describes the structure of the user
   var userPat = new RegExp("^" + word + "(\\." + word + ")*$");

   // On sépare utilisateur et domaine
   var emailPat = /^(.+)@(.+)$/;
   var matchArray = emailStr.match (emailPat);
   if (matchArray == null) {
      // Too many/few @'s or something; basically, this address doesn't
      // even fit the general mould of a valid e-mail address.
      alert ("L'adresse e-mail ne semble pas correcte,\nvérifiez les @ et les .");
      return false;
   }
   var user = matchArray[1];
   var domain = matchArray[2];

   // On teste la validité des caractéres dans la partie utilisateur (0-127).
   for (i = 0; i < user.length; i++) {
      if (user.charCodeAt(i) > 127) {
         alert("L'adresse e-mail ne semble pas correcte,\nLe nom d'utilisateur contient des caractéres non valides.");
         return false;
      }
   }
   // On teste la validité des caractéres dans la partie domaine
   for (i = 0; i < domain.length; i++) {
      if (domain.charCodeAt(i) > 127) {
         alert("L'adresse e-mail ne semble pas correcte,\nLe nom de domaine contient des caractéres non valides.");
         return false;
      }
   }

   // On vérifie que le nom d'utilisateur est correct
   if (user.match(userPat) == null) {
      alert ("L'adresse e-mail ne semble pas correcte,\nLe nom d'utilisateur ne semble pas être correct.");
      return false;
   }

   // Si l'adresse e-mail pointe sur une IP, on vérifie que l'IP est valide
   var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;
   var IPArray = domain.match (ipDomainPat);
   if (IPArray != null) {
      // Adresse IP
      for (var i = 1; i <= 4; i++) {
         if (IPArray[i] > 255) {
            alert("L'adresse e-mail ne semble pas correcte,\nL'adresse IP destination n'est pas valide.");
            return false;
         }
      }
      return TRUE;
   }

   // Le domaine est un nom symbolique. Vérifie sa validité.
   var atomPat = new RegExp ("^" + atom + "$");
   var domArr = domain.split (".");
   var len = domArr.length;
   for (i = 0; i < len; i++) {
      if (domArr[i].search(atomPat) == -1) {
         alert("L'adresse e-mail ne semble pas correcte,\nLe nom de domaine ne semble pas valide.");
         return false;
      }
   }

   // le nom de domaine semble correct, on vérifie qu'il se termine par un nom de domaine
   // connu (com, edu, gov) ou par 2 caractéres, représentant le pays (fr, uk, de), et qu'il y a un
   // and that there's a hostname preceding the domain or country.
   var knownDomsPat = /^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|tv|museum)$/;
   if (checkTLD && domArr[domArr.length-1].length != 2 && domArr[domArr.length-1].search(knownDomsPat) == -1) {
      alert("L'adresse e-mail ne semble pas correcte,\nL'adresse doit se terminer par un domaine classique ou par les 2 caractéres d'un pays.");
      return false;
   }

   // Make sure there's a host name preceding the domain.
   if (len < 2) {
      alert("L'adresse e-mail ne semble pas correcte,\nVous n'avez pas saisi l'addresse.");
      return false;
   }
   // Le nom est valide
   return true;
}