It is possible to prevent visitors from subscribing with a free email (with domains such as gmail.com, hotmail.com, facebook.com, etc.) or with a disposable email (a fake email that will be used only once).
To do so, we'll use the Wisepops JS callbacks feature to download a list of free or disposable email providers, and ensure that the listed domains are not used in the email field.
Forbid Disposable Emails in Your Signup Form
From our editor, create a new JS callback listening for the event
Before popup display
:
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.
Create a second callback listening for the Before form submit event.
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! Your final config should look like the one below.
You can learn more about how to write custom validations for your forms here.
Forbid Free Email Providers in Your Signup Form
From our editor, create a new JS callback listening for the event
Before popup display
:
Copy and paste the following snippet in the script area:
// Get list of free email domains
var xhr = new XMLHttpRequest();
xhr.open('GET', 'https://wisepops.gitlab.io/free-email-providers/list.txt', true);
xhr.onload = function () {
if (xhr.status === 200) {
window.wisepopsFreeEmailDomains = xhr.responseText.split("\n");
}
};
xhr.send();
When the popup is being displayed, we will load the list of free email providers from a public resource maintained by Wisepops.
The list is loaded asynchronously – meaning that it won't delay the popup.
Create a second callback listening for the Before form submit event.
Copy and paste the following snippet into the callback's script:
// Prevent sign-up with a free email
// This script uses the list fetched by the before-popup-display callback
var isFreeEmail = false;
var emailField = event.target.elements['email'];
var emailParts = emailField.value.split('@');
if (emailParts.length === 2 && window.wisepopsFreeEmailDomains) {
isFreeEmail = window.wisepopsFreeEmailDomains.indexOf(emailParts[1]) > -1;
}
if (emailField) {
if (isFreeEmail) {
emailField.setCustomValidity('Please use a professional email.');
} 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: "Please use a professional email.”
And voila! Your final config should look like this:
You can learn more about how to write custom validations for your forms here.
If you need any help or advice, get in touch with our Customer Support team.