AnsweredAssumed Answered

Restrict Free Email for Form Submission

Question asked by 19a21cff4515dc5b3226bb30cd384c21ee0122e4 on Jan 23, 2017
Latest reply on Jan 23, 2017 by sanford.whiteman

Hi, I have found the javascript provided on the Marketo Developer documentation about restricting free email(like gmail.com, yahoo.com etc.) upon form submission. However, when I inserted the script before the end of head card, and tested the form, it didn't work as it should.

Can someone let me know where I did wrong, the place I inserted the code, or I need to clear up the form CSS custom code?(which I did, but still didn't work) or something else?

Thank you!

Here's the script:

<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>

Here's the source I get the code from:

http://developers.marketo.com/blog/restrict-free-email-domains-on-form-fill-out/

Here's the test landing page and form:

http://get.evault.com/Testing-Business-Email-Error-Msg_ttest.html

 

Appreciated any feedback!

Outcomes