Solved

[How To] Require A Business Email In Your Unbounce Forms


Userlevel 7
Badge +1
  • Former Community Manager @ Unbounce
  • 831 replies

From time to time, it’s a good option to prevent “free” or “personal” email address form submissions in your landing pages – this really depends on what kind of campaign you’re running.

This has come up here in the community before (here, here, and here) so I thought it might be a good idea to create a single post with the most up-to-date solution for this.

In this post shared by @Mark_Wainwright (one of Unbounce’s superstar software developers), he demonstrates how to add custom validation in Unbounce form fields. Here are the instructions to prevent free/personal email address form submissions in your Unbounce landing pages:

Apply the rule to the form field

Step 1. Copy the following script and paste it into the Javascripts section of the builder, placement: BEFORE BODY END TAG:

<script>
  window.ub.form.customValidators.nonWebmailEmail = {
    isValid: function(value) {
      return /\@(?!(me|mac|icloud|gmail|googlemail|hotmail|live|msn|outlook|yahoo|ymail|aol)\.)/.test(value.toLowerCase());
    },
    message: 'Please enter your work email address',
  };
</script>
<script>
window.module.lp.form.data.validationRules['my_form_field'].nonWebmailEmail = true;
</script>

Step 2. Replace my_form_field with the ID of the form field you want to apply the rule to

View the original post here, which goes into more detail of adding custom validations to form fields.


Boom! You’re done. 💥

icon

Best answer by Bruna_Tavares 29 September 2020, 23:13

View original

30 replies

Badge

Does anyone know what code to add onto a smart builder page and where this gets added? The script i use for normal builder is not working.

Userlevel 2
Badge

@Vic03 @TomAdbetter 

Hope you are all doing well! I was able to reach out to our Tech Team and you may be able to omit those emails that the code is blocking from heading over to HubSpot. Try disabling the “Non-HubSpot Forms” feature in HubSpot settings. 

https://knowledge.hubspot.com/forms/use-non-hubspot-forms#supported-forms

This is an explanation from their product team of why all leads are sent over:

https://community.hubspot.com/t5/Lead-Capture-Tools/Hubspot-Collecting-Multiple-Incomplete-Gravity-Form-Forms/m-p/202862/highlight/true#M1626

Hope this helps!

@TomAdbetter and @Vic03 we also have the same problem with Hubspot. Did either of you find a solution?

Hi @Metro_Group 

Unfortunately, My team and I didn't find a solution to this problem. We decided to embed the form instead of using the Unbounce integration. However, we still receive spam leads from this solution, mostly from Display ads, but we don't have the integration problem anymore. 

Sorry for not having a clear solution for this problem. 
 

Badge

@TomAdbetter and @Vic03 we also have the same problem with Hubspot. Did either of you find a solution?

Hi, anyone knows a code do to validate personal emails too (gmail, yahoo, hotmail, etc) and not only work emails? 

 

Hi @TomAdbetter,
I have the same problem with Hubspot. Did you find a solution to resolve the problem ?

Hi All - thanks for the script! This is working to block free domain emails in Unbounce, apart from the leads that attempt to use free emails seem to still be sent through to Hubspot using the Unbounce integration. i.e. they’re not showing in the “leads” section on Unbounce (so not being captured), but the lead data is still being passed through to Hubspot.

I’m assuming this is because the integration with Hubspot happens before the check in the form happens? Has anyone experienced this before and knows a fix?

I believe this may be something better asked to a developer on your side… I would think this would be possible but don’t know enough to say for certain.

Thanks,

Allison Woizeschke

Digital Caffeine | DigitalCaffeineGroup.com | 515.441.6198

Give your marketing and search a buzz.

Is it possible to adjust the script to somehow capture emails that are formatted a certain way? Reason being, we have A LOT of spam leads coming in that are all formatted like “FirstMLast@randomdomain.com.” Obviously, the values change (ErikJSmith, GeorgeWBush, etc…) but the formatting does not. We can use this script above, but also don’t want to lose conversions for those with legitimate gmail, hotmail, etc… email addresses. I know it’s a long shot, but worth asking. Thanks.

Can someone take a look at my page? I have checked and it looks like I added the script correctly but it is not triggering when I test the form.

Hi Tina,

Can you share the landing page URL? I’d be happy to take a look. 🙂

Can you share which code you used? The script I’ve seen above isn’t working!

Thanks,
Tina

Can someone advise? This script is not working for me:

Hey Jess! Looks like I must have pasted an old code or perhaps the wrong way. It is working now. Thanks for your response.

Hey Jess! Sure thing. Right now, I’m performing it on a test page before I go and utilize it on a client’s landing page. This is the code I have inserted in the body tag:

work_email is the name of the form fill id where the participant inputs their email. When I practice this, I still get the window that verifies the form fill submission rather than the “Please enter your work email address” showing.

Userlevel 7
Badge +1

Hey Drew 👋

Happy to help out here, can you elaborate a bit on what you’re seeing? And if you could share the code you’re using that would help as well!

Thanks!

-Jess

Hey Bruna!
I gave this a try today, but it didn’t perform as expected. I’ve followed the instructions in this thread without much luck. Can you help me out?

Hey friends,

Bruna from Unbounce here! In case you are wondering, I just want to confirm that the following script is currently working

<script>
  window.ub.form.customValidators.nonWebmailEmail = {
    isValid: function(value) {
      return /\@(?!(me|mac|icloud|gmail|googlemail|hotmail|live|msn|outlook|yahoo|ymail|aol)\.)/.test(value.toLowerCase());
    },
    message: 'Please enter your work email address',
  };
</script>
<script>
window.module.lp.form.data.validationRules['my_email_form_field_id_goes_here'].nonWebmailEmail = true;
</script>

Placement: Before Body End Tag

I tried this one. But not working.

Userlevel 7
Badge +1

That’s awesome, @Elliot_Sheen! I’d love to hear how that performs! 💪

To answer your question, YES! Sorry I didn’t respond sooner!

-Jess

Userlevel 7
Badge +1

Hey Marius! I think I have all the info you’re looking for.

As per your screenshot above, in this instance you’ll want to replace my_form_field with email, which is the form field ID.

Here’s a screenshot to explain it a bit better:

Let me know if it works!

-Jess

Thanks @Jess, super useful! Presumably this works with popup forms also?

If so the timing of this is perfect. We just launched a data studio dashboard with a lead capture element requesting Business Email, but are getting a lot of personal / generic emails.

Hi Jess,

Yes of course, thanks for asking.

<script>
  window.ub.form.customValidators.nonWebmailEmail = {
    isValid: function(value) {
      return /\@(?!(me|mac|icloud|gmail|googlemail|hotmail|live|msn|outlook|yahoo|ymail|aol)\.)/.test(value.toLowerCase());
    },

    message: 'Please enter your work email address',
  };
</script>

<script>
  window.ub.form.validationRules.lp-pom-form-19.nonWebmailEmail = true;
</script>

In red you see where I added the form ID.

I forgot to attach a screenshot of the Form Field found under “Edit Form Fields”, so here it is.

Thank you for taking the time.

Best wishes,

Marius

Userlevel 7
Badge +1

Hi Marius,

Could you share the code you implemented for us to check? Thanks 🙂

-Jess

Marius got my questions! I’m also stuck on this point.

Reply