Skip to content

Instantly share code, notes, and snippets.

@MurtzaM
Created September 9, 2014 23:49

Revisions

  1. MurtzaM created this gist Sep 9, 2014.
    37 changes: 37 additions & 0 deletions preventNonBusinessEmailSubmission.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,37 @@
    //This script prevents Marketo form submission if a user enters non-business email (Gmail, Hotmail, Yahoo, etc.)
    //It will work on any page with a Marketo form, and runs when the form is ready
    //For further info, please see Marketo form documentation, http://developers.marketo.com/documentation/websites/forms-2-0/
    //Prepared by Ian Taylor and Murtza Manzur on 9/9/2014

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