Require Business Email Address on Forms | Community
Skip to main content
Trevor_Parsell
Level 5
January 18, 2018
Solved

Require Business Email Address on Forms

  • January 18, 2018
  • 1 reply
  • 15250 views

Hello,

I found the script below in this discussion: How do I require a BUSINESS email

I pasted the script in my Marketo landing page template and tested the form with a Yahoo email address and it still is allowing me to submit the form. Where exactly should this script be placed to reject non-business email addresses for particular forms? Any help would be greatly appreciated.

<script>
(function (){
  // Please include the email domains you would like to block in this list
  var invalidDomains = ["@yahoo.","@hotmail.","@live.","@aol.","@msn.","@outlook."];
  MktoForms2.whenReady(function (form){
   form.onValidate(function(){
   var email = form.vals().Email;
   if(email){
   if(!isEmailGood(email)) {
   form.submitable(false);
   var emailElem = form.getFormElem().find("#Email");
   form.showErrorMessage("Must be Business email.", emailElem);
  }else{
   form.submitable(true);
  }
  }
  });
  });
  function isEmailGood(email) {
   for(var i=0; i < invalidDomains.length; i++) {
   var domain = invalidDomains[i];
   if (email.indexOf(domain) != -1) {
   return false;
  }
  }
   return true;
  }
})();
</script>



Thanks!

Trevor

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by SanfordWhiteman

Lawdy, how I hate that code.

It should have barebones functionality, though.  Are you being sure to include it after the <script> that loads forms2.min.js? On a Marketo LP, you'll want to put this just inside the closing </body> tag (because Mkto may inject the forms2.min.js at any point in the body content).

1 reply

SanfordWhiteman
SanfordWhitemanAccepted solution
Level 10
January 18, 2018

Lawdy, how I hate that code.

It should have barebones functionality, though.  Are you being sure to include it after the <script> that loads forms2.min.js? On a Marketo LP, you'll want to put this just inside the closing </body> tag (because Mkto may inject the forms2.min.js at any point in the body content).

Trevor_Parsell
Level 5
January 19, 2018

Thanks, Sanford. I just needed to move it down the page and it is now working.

Do you hate the code because it prevents potentially good leads from filling out forms if they prefer to use a non-business email address? Are there other downsides?

Just curious as I am not a huge fan of doing this although there are some scenarios where it will be useful.

Thanks!

SanfordWhiteman
Level 10
January 19, 2018

It's not about the concept (it has its uses) but the implementation.

  • There are 1000s of free domains, but the code only (mis)identifies a few (the seminal list is the Freemail list).
  • The pattern matching is incorrect. If my email address is sandy@live.event24.com, that isn't a Microsoft domain; if my company sets up a domain for outlook users @outlook.college.edu, that isn't an Outlook 365 domain. The freemail providers don't actually own all the instances of their domain at all levels of the domain tree and under all TLDs!
  • The function name isEmailGood is frustrating, because it isn't validating the email as a whole.