How to prevent common email typos

Sometimes you want to show an error if a user types in carl@gail.com (instead of carl@gmail.com). You can use this Custom JS to detect common email typos and show an error message to the user. We run this in Box JS After Form Validation to add additional validation on top of the basic validation already configured for your forms. For more information on the form processing pipeline, see Custom JS Overview for Developers.

Custom JS Boxes – Event Trigger “After Form Validation”

var wrongMails = ["Gogglemail", "googlmail", "goglemail", "Hotmial", "Hotmal", "Hoitmail", "Homail", "Hotnail", "Hotrmail", "Hotmil", "Hotmaill", "Ntlwolrd", "ntlword", "ntl.world", "ntlwrold", "Tiscale", "tiscalli", "Tiscally", "Tiscaly", "Btinterent", "btinternt", "Yaho.", "Uahoo", "ayhoo", "ymial", "ymal", "ymil", "ymaill", "ynail", "yail", "gmial", "gmal", "gmil", "gnail", "gmaill", "gail"];

var email = x.email;
var isValid = true;

wrongMails.forEach(function(mail){
   if(email) {
      var emailDomain = email.split("@")[1].toLowerCase();
      if(emailDomain.includes(mail.toLowerCase())) {
         isValid = false;
      }
   }
});

if(!isValid) {
   showError("please enter a valid email address");
   return false;
}