SOLVED

Re: Implementing form data validation for email?

Go to solution
Robb_Barrett
Marketo Employee

Re: Implementing form data validation for email?

One thing to remember is that if you ever go with a social login you don't want to force work-only emails. I don't know about you, but I use my personal email for LinkedIn.

Robb Barrett
Andy_Varshneya1
Level 9

Re: Implementing form data validation for email?

That's a good point Robb. I'll have to keep that in mind, though I don't imagine the script impacting that flow as if leads are using social login, they should be created in our database via the API.

Anonymous
Not applicable

Re: Implementing form data validation for email?

We use a custom javacript as hidden HTML in the form itself. It's actually quite easy. Here's what we throw in:

Business domain validation code for Forms 2.0

Note: Remember to change the highlighted text with form-specific information. You can put whatever "public" email domains you wish directly into the list of invalid domains.

<script type="text/javascript" src="http://info.ascentis.com/js/public/jquery-latest.min.js" language="Javascript"></script>

<script src="//app-abj.marketo.com/js/forms2/js/forms2.js"></script>

<form id="mktoForm_355"></form>

<script>

  // set no conflict mode for jquery

  var $jQ = jQuery.noConflict();

    //edit this list with the domains you want to block

  var invalidDomains = ["@gmail.com","@yahoo.com","@live.com","@hotmail.com","@aol.com","@comcast.net","@earthlink.net","@msn.com","@sbcglobal.net","@bellsouth.net","@bellsouth.com","verizon.net","@me.com","@icloud.com"];

function isEmailGood() {

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

      if ( $jQ("#Email[value*=" + invalidDomains[i] + "]").length > 0) {

          return false;

      }

    }

return true;

}

MktoForms2.loadForm("//app-abj.marketo.com", "your marketo user ID", 355, function(form){

  1. form.onSubmit(function() {

if(!isEmailGood()) {

                // just in case this doesn't work, change "form.showErrorMessage" to "alert" form.showErrorMessage("Business email domain required");                form.submitable(false);        } else { form.submitable(true);        }});

  1. form.onValidate(function() {

form.submitable(true);

        });

});

</script>

SanfordWhiteman
Level 10 - Community Moderator

Re: Implementing form data validation for email?

The authoritative list of free (frequently interpreted as "non-business," though there are plenty of examples to the contrary) domains is the Freemail list. Also, that isn't really the right way to use the Forms 2.0 API.  But we digress...