5 Replies Latest reply on Jan 19, 2018 5:26 PM by Sanford Whiteman

    Require Business Email Address on Forms

    Trevor Parsell



      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.


      (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){
         var email = form.vals().Email;
         if(!isEmailGood(email)) {
         var emailElem = form.getFormElem().find("#Email");
         form.showErrorMessage("Must be Business email.", emailElem);
        function isEmailGood(email) {
         for(var i=0; i < invalidDomains.length; i++) {
         var domain = invalidDomains[i];
         if (email.indexOf(domain) != -1) {
         return false;
         return true;




        • Re: Require Business Email Address on Forms
          Sanford Whiteman

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

            • Re: Require Business Email Address on Forms
              Trevor Parsell

              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.



                • Re: Require Business Email Address on Forms
                  Sanford Whiteman

                  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.
                    • Re: Require Business Email Address on Forms
                      Trevor Parsell

                      Hey Sanford,


                      I see what you mean. So would it make more sense to include the larger list of free email domains and to change the script to only block "@live.com" instead of "@live."


                      Example:  var invalidDomains = ["@yahoo.com","@hotmail.com","@live.com","@aol.com","@msn.com","@outlook.com"];


                      This should solve for the sandy@live.event24.com and @outlook.college.edu scenarios.


                      Thanks for your help!

                        • Re: Require Business Email Address on Forms
                          Sanford Whiteman

                          No, that'll still bug out should someone have a username like jill@outlook.comcorp.edu. The domains need to be firmly anchored to the right-hand-side of the email address.


                          Also, did I mention the original code is case-sensitive, so joe@YAHOO.COM is considered valid?  That's an even bigger problem than the rest, really.


                          This is a much tighter and more accurate function:


                          function inDomainList(email,domains){
                            return domains
                                return new RegExp('@'+domain+'$','i');
                                return reDomain.test(email);


                          then pass the domain list to the function (this is better practice than requiring the domain list to be up-scope, not that I don't do that myself sometimes):


                          var freemailDomains = ["yahoo.com","hotmail.com","live.com","aol.com","msn.com","outlook.com"];
                          if ( inDomainList(email,freemailDomains) ) {
                            /* it's in the list of domains you don't like */