SOLVED

Re: Require Business Email Address on Forms

Go to solution
Katherine_Nguye
Level 1

Re: Require Business Email Address on Forms

Hi Sanford,

Thanks for the insightful information! I was trying to look for a solution that solves for the concerns you shared.

So, I've included this in a Marketo LP and ran a few tests. It's properly blocking out "gmail.com," "aol.com," etc in line 14. But, it's not blocking emails from that larger list you shared, from freemail/free.txt at master · willwhite/freemail · GitHub 

Can you advise on how we can block all emails seen in that list?

Thank you!

SanfordWhiteman
Level 10 - Community Moderator

Re: Require Business Email Address on Forms

First you'd need to make sure the free.txt file is uploaded to Design Studio (for forms on Marketo LPs) and/or to your corporate site (for embedded forms).

Trish_ITRenew
Level 1

Re: Require Business Email Address on Forms

I added this code to LP template at bottom above final </body> tag.

<script>
function inDomainList(email,domains){ return domains .map(function(domain){ return new RegExp('@' + domain.replace('.','\\.') + '$','i'); }) .some(function(reDomain){ return reDomain.test(email); });}MktoForms2.whenReady(function(form){ var freemailDomains = ["yahoo.com","hotmail.com","live.com","aol.com","msn.com","outlook.com","gmail.com"], errorFreemail = "Must be Business email."; /* no need to touch below this line */ var formEl = form.getFormElem()[0], emailEl = formEl.querySelector("input[name='Email']"), emailJq = MktoForms2.$(emailEl); form.onValidate(function(native){ if (!native) return; var currentValues = form.getValues(), currentEmail = currentValues.Email; if ( inDomainList(currentEmail, freemailDomains) ) { form.submittable(false); form.showErrorMessage(errorFreemail, emailJq); } else { form.submittable(true); } });});
</script>

 

I then loaded the free.txt file to design studio Images and files.  

 

The main ones are working and won't allow me to use on a form "yahoo.com","hotmail.com","live.com","aol.com","msn.com","outlook.com","gmail.com"

 

but if I  fill out form with one of the other domains on free.txt list (for example trish@1nsyncfan.com) it was accepted. 

 

So hmm, not sure what I am doing wrong. do I need to put .txt file in a specifically named folder for code to see it?

 

thanks!

Trish

SanfordWhiteman
Level 10 - Community Moderator

Re: Require Business Email Address on Forms

Hard to read your code with the line breaks taken out! But doesn't look like it's calling in the remote file at all. This is different code.
TrishVoskoSpear
Level 2

Re: Require Business Email Address on Forms

Hi Sandford,

OH - I misunderstood then!

 

I just copied and pasted what you put in this topic string in response to someone else about this code block;

 

"To combine the original logic with the fixed validator function:"

<script>function inDomainList(email,domains){  return domains    .map(function(domain){      return new RegExp('@' + domain.replace('.','\\.') + '$','i');    })    .some(function(reDomain){      return reDomain.test(email);    });}MktoForms2.whenReady(function(form){  var freemailDomains = ["yahoo.com","hotmail.com","live.com","aol.com","msn.com","outlook.com","gmail.com"],      errorFreemail = "Must be Business email.";  /* no need to touch below this line */  var formEl = form.getFormElem()[0],      emailEl = formEl.querySelector("input[name='Email']"),      emailJq = MktoForms2.$(emailEl);  form.onValidate(function(native){    if (!native) return;    var currentValues = form.getValues(),        currentEmail = currentValues.Email;    if ( inDomainList(currentEmail, freemailDomains) ) {      form.submittable(false);      form.showErrorMessage(errorFreemail, emailJq);    } else {      form.submittable(true);    }  });});</script>

 

and make sure the free.txt file is loaded into Design Studio.  I assumed code covered both issues. so i am missing the code to call the file- can you help with that and tell where also where to add to above code or does it completely replace?

 

As you can tell I am not a developer but learning to do a bit more. 

 

Trish

 

 

TrishVoskoSpear
Level 2

Re: Require Business Email Address on Forms

here it is a bit prettier:

TrishVoskoSpear_0-1613083398213.png

 

SanfordWhiteman
Level 10 - Community Moderator

Re: Require Business Email Address on Forms

If you just copy it from view-source and then paste it into the Insert/Edit Code Sample window, that's best.
TrishVoskoSpear
Level 2

Re: Require Business Email Address on Forms

@SanfordWhiteman 

Ah - thanks for the tip!  Here is code I am using (stolen from you 😁) to list specific domains to not allow on forms. Do i add code to this to include the long list on my free.txt file I have uploaded to Images and Files? Or is it a complete different block of code I need to add to my templates. 

<script > function inDomainList(email, domains) {
    return domains.map(function(domain) {
        return new RegExp('@' + domain.replace('.', '\\.') + '$', 'i');
    }).some(function(reDomain) {
        return reDomain.test(email);
    });
}
MktoForms2.whenReady(function(form) {
    var freemailDomains = ["yahoo.com", "hotmail.com", "live.com", "aol.com", "msn.com", "outlook.com", "gmail.com"],
        errorFreemail = "Must be Business email."; /* no need to touch below this line */
    var formEl = form.getFormElem()[0],
        emailEl = formEl.querySelector("input[name='Email']"),
        emailJq = MktoForms2.$(emailEl);
    form.onValidate(function(native) {
        if (!native) return;
        var currentValues = form.getValues(),
            currentEmail = currentValues.Email;
        if (inDomainList(currentEmail, freemailDomains)) {
            form.submittable(false);
            form.showErrorMessage(errorFreemail, emailJq);
        } else {
            form.submittable(true);
        }
    });
}); < /script>

 

 

Thanks for all your help!

TrishVoskoSpear
Level 2

Re: Require Business Email Address on Forms

hmm, now code in the previous format  i inserted (with line breaks) not working but working when all on one line like i copied from your post:

 

<script>function inDomainList(email,domains){  return domains    .map(function(domain){      return new RegExp('@' + domain.replace('.','\\.') + '$','i');    })    .some(function(reDomain){      return reDomain.test(email);    });}MktoForms2.whenReady(function(form){  var freemailDomains = ["yahoo.com","hotmail.com","live.com","aol.com","msn.com","outlook.com","gmail.com"],      errorFreemail = "Must be Business email.";  /* no need to touch below this line */  var formEl = form.getFormElem()[0],      emailEl = formEl.querySelector("input[name='Email']"),      emailJq = MktoForms2.$(emailEl);  form.onValidate(function(native){    if (!native) return;    var currentValues = form.getValues(),        currentEmail = currentValues.Email;    if ( inDomainList(currentEmail, freemailDomains) ) {      form.submittable(false);      form.showErrorMessage(errorFreemail, emailJq);    } else {      form.submittable(true);    }  });});</script>

 

Trish_ITRenew
Level 1

Re: Require Business Email Address on Forms

 

Hi @SanfordWhiteman   this code below is working on my LP templates but I would also like to figure out what code needs to be added to also not allow domains from the free.txt file. You mentioned that was different code. Do you add to this or is it completely different code?

 

<script>
function inDomainList(email, domains) {
return domains.map(function(domain) {
return new RegExp('@' + domain.replace('.', '\\.') + '$', 'i');
}).some(function(reDomain) {
return reDomain.test(email);
});
}
MktoForms2.whenReady(function(form) {
var freemailDomains = ["yahoo.com", "hotmail.com", "live.com", "aol.com", "msn.com", "outlook.com", "gmail.com"],
errorFreemail = "Must be Business email."; /* no need to touch below this line */
var formEl = form.getFormElem()[0],
emailEl = formEl.querySelector("input[name='Email']"),
emailJq = MktoForms2.$(emailEl);
form.onValidate(function(native) {
if(!native) return;
var currentValues = form.getValues(),
currentEmail = currentValues.Email;
if(inDomainList(currentEmail, freemailDomains)) {
form.submittable(false);
form.showErrorMessage(errorFreemail, emailJq);
} else {
form.submittable(true);
}
});
});
</script>

 

 

thanks!

Trish