How do I require a BUSINESS email (and reject form fills using gmail or yahoo email addresses for the required email) | Community
Skip to main content
March 3, 2016
Question

How do I require a BUSINESS email (and reject form fills using gmail or yahoo email addresses for the required email)

  • March 3, 2016
  • 2 replies
  • 12735 views

I need a quick answer on how to require a business email. How do I set up this logic in my form fill?

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

2 replies

March 3, 2016

Add this piece of javascript code to your page

<script>
(function (){
  // Please include the email domains you would like to block in this list
  var invalidDomains = ["@gmail.","@yahoo.","@hotmail.","@live.","@aol.","@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>
Josh_Hill13
Level 10
March 3, 2016

cool.

Keep in mind this is a common question and if you search, there are a lot of answers. Your web dev can do this for you.

Level 2
March 10, 2016

Is there a way to prevent people from putting in random information, such as "ABC" for "123" for any of the fields?

SanfordWhiteman
Level 10
March 10, 2016

Neither of those strings are "random" in a company name, street address, or postal code.  In a first or last name, probably.  But just because someone fills in fake first/last name data doesn't mean they are a fake lead.  If you're really concerned about this, you can filter anything you want using Forms 2.0 JS. I'd caution, as with the freemail topic, that you end up grabbing a few low-hanging fruits and have a false sense that everything else is somehow legit (even though there are thousands of freemail providers).