Forbid Disposable Emails in Your Signup Form

Lisa Fockens Updated by Lisa Fockens

It is possible to prevent visitors from subscribing with a disposable email (a fake email that will be used only once). We will use the Wisepops JS callbacks feature to download a list of disposable email providers, and ensure that the listed domains are not used in the email field.

Step 1: 

From our editor, create a new JS callback listening for the event Before popup display:

Step 2:

Copy and paste the following snippet as the script of the created callback:

// Get list of disposable email domains
var xhr = new XMLHttpRequest();
xhr.open('GET', 'https://raw.githubusercontent.com/ivolo/disposable-email-domains/master/index.json', true);
xhr.responseType = 'json';
xhr.onload = function () {
  if (xhr.status === 200) {
    window.wisepopsDisposableEmailDomains = xhr.response;
  }
};
xhr.send();

When the popup is being displayed, we will load the list of disposable email providers from the open source project ivolo/disposable-email-domains.

This fetched list is loaded asynchronously – meaning that it won't delay the display of the popup.

Step 3:

Create a second callback listening for the Before form submit event.

Step 4:

Copy and paste the following snippet into the callback's script:

// Prevent sign-up with a disposable email
// This script uses the list fetched by the before-popup-display callback
var isDisposableEmail = false;
var emailField = event.target.elements['email'];
var emailParts = emailField.value.split('@');
if (emailParts.length === 2 && window.wisepopsDisposableEmailDomains) {
  isDisposableEmail = window.wisepopsDisposableEmailDomains.indexOf(emailParts[1]) > -1;
}
if (emailField) {
  if (isDisposableEmail) {
    emailField.setCustomValidity('This domain is not allowed');
  } else {
    emailField.setCustomValidity('');
  }
}

Here we will try to match the filled email domain against the previously fetched lists. If a match is found, we will display this error message: "This domain is not allowed.” 

You can learn more about how to write custom validations for your forms here.

You're done! You final config should look like the one below.

If you need any help or advice, get in touch with our Customer Support team.

How did we do?

Fire the Facebook Pixel When a form is Submitted

Display a Popup Only After Another One Has Been Seen (or Clicked)

Contact