Reject email addresses from specific domains

Version 5

    Some companies sending campaigns to specific audiences would like to reject  email addresses

    from specific domains when users fill out a form on a landing page.

     

    The solution is a simple JavaScript containing a list of invalid domains.

     

    Below is an example developed by Marketing Developer Murtza Manzur. Please add the following script to your landing page using the Custom HTML section in the Landing Page Editor.

    Please ensure that you have access to an experienced JavaScript developer.

    Marketo Technical Support is not set up to assist with troubleshooting JavaScript.

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