How to block non-professional emails from Webflow forms

Tutorial
March 20, 2023
3 min
Blocking icons with the Yahoo, Google, and Outlook logos
Key points

Do you want to block submissions from your Webflow forms to gmail addresses, hotmail, or Yahoo because the leads are unqualified?

In this tutorial, you will learn how to create a list of email domain names that will be blocked when submitting your Webflow forms.

Prefer videos? Watch our French tutorial on YouTube!

Using Finsweet's Hack #18 for Webflow

Finsweet's hack 18 will allow you, in just three simple steps, to add this feature (with JavaScript code) to any Webflow site. This solution does not require any additional tools and is 100% free. Thank you, Finsweet 🙌

1. Copy and paste the code into your site

To use this technique, you must copy and paste the JavaScript code below into the "before <!-- fs-richtext-ignore --></body> tag" of the Webflow page containing the form for which you wish to block non-business emails.

<!-- F’in sweet Webflow Hacks -->
<script>
// when the DOM is ready
$(document).ready(function() {
  // make an array of invalid domains
  const invalidDomains = ['gmail.com', 'AJOUTER-ICI', 'hotmail.com', 'competitor.com'];

  // get the submit button
  const submitBtn = $('.hack-button');
  // on submit button click
  submitBtn.click(()=>{
    // get the email field
    const email = $('.hack18-email');
    // split email at '@' character to get domain
    const domainPart = email.val().split('@')[1]; 
  
    // if the domain exists in the invalidDomains array
    if(invalidDomains.indexOf(domainPart) !== -1) {
      // clear email field
      email.val('');
      // add a 'use business mail' placeholder
      email.attr('placeholder','Please enter a business email');
      // prevent form submission
      return false;
    }
    else{	// else if email is not invalid
      // submit form
      return true;
    }
  });
});
</script>

2. Customize the code

Next, you need to customize the code to decide which email addresses you want to block. Gmail address? Or for example, the email address of your competitors who might be looking to access your free content?

On the line "const invalidDomains = [ 'ADD-HERE'];" replace the value ADD-HERE with the root of the email address you wish to exclude.

If you want to exclude emails coming from Google addresses, simply replace "ADD-HERE" with "gmail.com".

3. Add CSS classes to your button and email field

The final step in this tutorial is to ensure the JavaScript code can identify the submit button and the email field of your Webflow form. To do this, you just need to:

  1. Add the CSS class .hack-button to the submit button of your form
  2. Add the class .hack18-email to your email field on your Webflow form

And there you go, it’s time for you to test it out!

Bonus: Customize the placeholder message of your Webflow form

In the JS code, replace the phrase "Please enter a business email" with your desired message. For example: "Professional email address"

That’s it, you now know how to prevent the submission of your Webflow forms from any email address.

Florian Bodelot
Florian Bodelot
Co-founder

Suggested articles

Webflow Localization, Credial's Use Case
Documentation
Webflow

Webflow Localization: Practical Guide & Credial's Use Case

Webflow Localization: Practical Guide & Credial's Use Case
Visuel showcasing digidop.fr switching to digidop.com
News
Digidop

Digidop.fr is now Digidop.com

Digidop.fr is now Digidop.com
Photo of the Digidop team with the Digidop Logo 2024
News
Digidop

A Look Back at an Exceptional 2024 and Vision 2025

A Look Back at an Exceptional 2024 and Vision 2025

Want to turn your website into your most valuable asset?

Contact us today