1. Home
  2. Integrations
  3. Marketing Automation
  4. Marketo Integration
  5. Code Snippets for Marketo Form Validation to Exclude Certain Email Domains

Code Snippets for Marketo Form Validation to Exclude Certain Email Domains

The following script can be used to add a validation rule to your Marketo Forms within PathFactory. This can be helpful in ensuring that visitors are submitting their business email addresses and not any personal or test emails.

To see more examples of code snippets, read Frequently Used External Code Snippets to Personalize Your PathFactory Experiences.

Note: This can only be added to custom HTML forms containing Marketo form embed codes.

See This Code In Action

Example of Error Displayed for Personal Email Address

Where to place the script?

This script can be added below the Marketo Form Code in your PathFactory Form library. The comma separated list of invalid domains in the section below that are In the section Optional and Editable Code Snippets, can be modified to match your specific use case.

Code Snippets

There are three sections of code snippets:

  1. Opening script.
  2. Optional and editable snippets.
  3. Closing script.

Opening Script (Not Editable)


  (function () {

    // Please include the email domains you would like to block in this list

    var invalidDomains = [

Optional and Editable Code Snippets






































































































































































Closing Script (Not Editable)


    MktoForms2.whenReady(function (form) {

      form.onValidate(function () {

        var email = form.vals().Email;

        if (email) {

          if (!isEmailGood(email)) {


            var emailElem = form.getFormElem().find(“#Email”);


              “Please use a valid corporate email address.”,



          } else {






    function isEmailGood(email) {

      for (var i = 0; i < invalidDomains.length; i++) {

        var domain = invalidDomains[i];

        if (email.indexOf(domain) != -1) {

          return false;



      return true;




Updated on July 24, 2023

Was this article helpful?

Need Support?
Can't find the answer you're looking for? Don't worry we're here to help!