How to Prevent Common Email Typos

Sometimes you want to show an error if a user types in, say, carl@gail.com (instead of carl@gmail.com).

With Digioh, you can add additional email validation to your forms that detects and prevents typos for the most popular email domains, such as Gmail, Hotmail, and Yahoo.

Use the Custom JavaScript below to detect common email typos and show an error message to the user. If you know that your audience tends to use certain email domains that aren’t covered by this JavaScript, you can customize this JavaScript with additional common typos by adding them to the wrongMails array.

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;
}
Related Reading: