SOLVED

Re: Limit Email Domains on Form Submission

Go to solution
Jon_Jagelsky
Level 2
We used the java script from this article on all of our landing pages with 1.0 forms in order to block personal email domains but in testing I'm finding that this same script does not work with new forms 2.0.

https://community.marketo.com/MarketoResource?id=kA650000000GtqvCAC

Anyone else running into this same issue or have any suggestions on how to block email domains with Forms 2.0?
Tags (1)
1 ACCEPTED SOLUTION
Kathi_Gosche
Level 4

One of my developers came up with this code that has worked for me. Depending on the way your button is designed, it may or may not work for you, but you can give it a try.

Replace your old validation code with the below:

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script type="text/javascript" charset="utf-8">
var $jQ = jQuery.noConflict();
var invalidDomains =
[
"hotmail.com",
"yahoo.com",
"aol.com",
"gmail.com",
];
$jQ(document).ready(function(){
if ($jQ('.mktoButtonRow').length == 0) {
window.setTimeout(function(){
emailValidation();
}, 500);
} else {
emailValidation();
}
});
$jQ('#Email').bind('blur', function(){
if (isEmailValid()){
var $error = $jQ(this).parent().find('.mktoError');
if ($error.length > 0) {
$error.fadeOut(200, function(){
$error.remove();
$jQ('#Email').removeClass('mktoInvalid');
});
}
}
});
function emailValidation() {
var $buttonRow = $jQ('.mktoButtonRow');
var submitText = $buttonRow.find('button').html();
var $replacement = $jQ('<input id="replacementButton" type="button" class="mktoButton" value="' + submitText + '" />');
$buttonRow.hide();
var buttonRowContents = $buttonRow.html();
$span = $jQ(buttonRowContents).html('');
var $replacementRow = $jQ('<div class="mktoFormRow" />').append($span.append($replacement));
$jQ('.mktoFormRow :last').after($replacementRow);
$jQ('#replacementButton').click(function(){
console.log('debug1');
if (!isEmailValid()) {
console.log('debug2');
var $error = $jQ('#Email').parent().find('.mktoError');
if ($error.length == 0) {
$error = getError('Please provide a business or institutional email address');
$jQ('#Email').after($error);
}
$error.fadeIn(200);
$jQ('#Email').removeClass('mktoInvalid').addClass('mktoInvalid');
return;
} else {
console.log('debug3');
$jQ('.mktoButtonRow button').trigger('click');
}
});
}
function isEmailValid() {
var email = $jQ('#Email').val().toLowerCase();
for(i=0; i < invalidDomains.length; i++) {
var invalidDomain = invalidDomains[i].toLowerCase();
if (email.indexOf(invalidDomain) !== -1) {
return false;
}
    }
return true;
}
function getError(message, detail) {
var $container = $jQ('<div class="mktoError" style="right: 0px; bottom: -47px; display: none" />');
var $arrow = $jQ('<div class="mktoErrorArrowWrap"><div class="mktoErrorArrow"></div></div>');
var $errorMessage = $jQ('<div class="mktoErrorMsg" />').html(message);
if (typeof detail == 'string' && $jQ.trim(detail) != '') {
$errorMessage = $errorMessage.append($jQ('<span class="mktoErrorDetail" />').html(detail))
}
return $container.append($arrow).append($errorMessage);
}
</script>

View solution in original post

22 REPLIES 22
Jason_Scott
Level 4
You can edit button when building the form in Marketo.  
Anonymous
Not applicable
This code works great, but is there a way to edit it so that the button is red instead of blue?
Hiram_Cruz
Level 2
Hi group, 

I'm trying to embed a form on a non-marketo LP with the javascript from this thread to exclude gmails & yahoo's ect.

I copy + pasted Egnet's code but can't get the form to render. Can someone please help point out what I'm doing wrong here? 

Here's my script: 



<script src="//learn.cpcstrategy.com/js/forms2/js/forms2.js"></script>
<form id="mktoForm_1200"></form>
<script>MktoForms2.loadForm("//learn.cpcstrategy.com", "006-GWW-889", 1200, function(form){
 
form.onValidate(function(valid) {
var email = form.getFormElem().find("#Email");
 
var validateEmail = function(email) {
var filters = [
"123mail","aol","att","bellsouth","charter","comcast","cox","earthlink","gmail","gmx","gmx","googlemail","hotmail","juno","live","mac","mail","me","mindspring","msn","optonline","pacbell","rediffmail","rocketmail","rogers","rr","sbcglobal","sympatico","telus","verizon","web","yahoo","ymail","zigmail","bigstring","bumpymail","centermail","centermail","discardmail","dodgeit","e4ward","emailias","fakeinformation","front14.","getairmail","ghosttexter","jetable","kasmail","link2mail","mailexpire","mailinator","mailmetrash","mailmoat","messagebeamer","mytrashmail","nepwk","nervmich","netmails","netzidiot","nurfuerspam","oneoffemail","pookmail","privacy","punkass","rmqkr","sharklasers","sneakemail","sofortmail","sogetthis","spam","spambob","spambob","spambob","spambog","spamex","spamgourmet","spamhole","spaminator","spammotel","spamtrail","trash-mail","trashymail","trashmail","yopmail","wuzup"
],
domain = email.substring(email.indexOf('@') + 1),
parts = domain.split('.');
 
for(var filter in filters) {
for(var i = 0, ln = parts.length; i < ln; i++) {
if(parts[i].toLowerCase() == filters[filter]) {
return false;
}
}
}
return true;
};
 
if(validateEmail(email.val())) {
form.submitable(true);
} else {
form.submitable(false);
form.showErrorMessage("Please provide a company email address.", email);
}
 
});
});
</script>
 





Anonymous
Not applicable
Has anyone had an issue with getting the form.showErrorMessage() to persist when users hit the ENTER key instead of the submit button?

For us, when users uses the ENTER key to submit the form, the message is rendered but quickly, but quickly disappears.  If the user clicks the SUBMIT button, the error message persists until the user edits the input box (correct behavior).

Any ideas how to make the ENTER key and SUBMIT button behave the same?

We've tested this only on a Mac, but same behavior exists in Safari, Firefox and Chrome.
Jason_Scott
Level 4
Thanks Enget!
Enget_Dang
Level 3
Hi Jon and Jason,

I haven't been able to get the script to work on a Marketo LP, only as an embedded form on a web page. Currently working on a solution to get it resolved on Marketo LPs. Jon, here is the form we are using with the current script: http://www.boaweb.com/contact-us/ 

Thanks!

Enget
Jason_Scott
Level 4
Jon or Enget,

Would either one of you be willing to share a live page with this script?

Thanks!
Jason
Jon_Jagelsky
Level 2
Hi Enget,

Thanks for sharing your code! I finally got around to testing last week and it worked as expected when embedding the form. I'm curious if you've had any success using this when placing the form directly on a Marketo LP? and how you got it to work? I tried using it with the drag and drop form and the script was causing the form to load twice on the page.

The problem is when using this and embeding the form I've lost the prefill functionality. 

I hate to gain one functionality but lose another. Would love to hear your thoughts.

Thanks!
Enget_Dang
Level 3
Also, this is not an April Fool's joke 😉
Enget_Dang
Level 3
I've had trouble with this script from IE as well. Caused some big headaches when attendees were trying to register for a webinar and couldn't submit their information.

Worked with our web developer to get this script working. Feel free to try and test. Used BrowserStack to test across browsers using the Marketo embed script. Insert after loadForm line:
 

form.onValidate(function(valid) {
var email = form.getFormElem().find("#Email");
 
var validateEmail = function(email) {
var filters = [
"gmail", "yahoo"
],
domain = email.substring(email.indexOf('@') + 1),
parts = domain.split('.');
 
for(var filter in filters) {
for(var i = 0, ln = parts.length; i < ln; i++) {
if(parts[i].toLowerCase() == filters[filter]) {
return false;
}
}
}
return true;
};
 
if(validateEmail(email.val())) {
form.submitable(true);
} else {
form.submitable(false);
form.showErrorMessage("Please provide a company email address.", email);
}
});
 
});</script>
Jon_Jagelsky
Level 2
Has anyone else found that this code does not work on IE 9 and below? Works fine in IE 10 & 11 but won't allow form submit no matter what the email address is in IE 9.

Was also wondering if anyone has altered the Marketo supplied script for form validation (#9 on here -http://developers.marketo.com/documentation/websites/forms-2-0/)  to work for Email address and would care to share. I haven't seen it out in the Community yet. Time to go brush up on my js knowledge...

  1. MktoForms2.loadForm("//app-sjqe.marketo.com", "718-GIV-198", 621, function(form){
  2.   //listen for the submit event
  3.   form.onSubmit(function(){
  4.     //get the values
  5.     var vals = form.getValues();
  6.     //Check your condition
  7.     if(vals.Country == "USA"&& vals.VehicleSize != "massive"){
  8.       //prevent form submission
  9.       form.submitable(false);
  10.       //Show error message, pointed at VehicleSize element
  11.       var vehicleSizeElem = form.getFormElem().find("#VehicleSize");
  12.       form.showErrorMessage("All Americans must have a massive vehicle", vehicleSizeElem);
  13.     }else{
  14.       //enable submission for those who met the criteria.
  15.       form.submitable(true);
  16.     }
  17.   });
  18. });
Anonymous
Not applicable
I've included an updated list of the most common personal, ISP and free email domains below. You can substitue the longer list for this short list in the example above:

"hotmail.com",
"yahoo.com",
"aol.com",
"gmail.com",

You can also find an extensive list (more than 3,500 as of this writing) at https://gist.github.com/tbrianjones/5992856

Most common personal, ISP and free email domains:

"123mail.org",
"aol.com",
"att.net",
"bellsouth.net",
"bigstring.com",
"blueyonder.co.uk",
"bt.com",
"btinternet.com",
"bumpymail.com",
"centermail.com",
"centermail.net",
"charter.net",
"comcast.net",
"cox.net",
"discardmail.com",
"dodgeit.com",
"e4ward.com",
"earthlink.net",
"email.com",
"emailias.com",
"facebook.com",
"fakeinformation.com",
"freeserve.co.uk",
"front14.org",
"games.com",
"getairmail.com",
"ghosttexter.de",
"gmail.com",
"gmx.com",
"gmx.de",
"gmx.net",
"google.com",
"googlemail.com",
"hotmail.co.uk",
"hotmail.com",
"hush.com",
"hushmail.com",
"inbox.com",
"jetable.net",
"juno.com",
"kasmail.com",
"lavabit.com",
"link2mail.net",
"live.co.uk",
"live.com",
"love.com",
"mac.com",
"mail.com",
"mailexpire.com",
"mailinator.com",
"mailmetrash.com",
"mailmoat.com",
"me.com",
"messagebeamer.de",
"mindspring.com",
"msn.com",
"mytrashmail.com",
"nepwk.com",
"nervmich.net",
"netmails.net",
"netzidiot.de",
"ntlworld.com",
"nurfuerspam.de",
"o2.co.uk",
"oneoffemail.com",
"optonline.net",
"orange.net",
"outlook.com",
"pacbell.net",
"pobox.com",
"pookmail.com",
"privacy.net",
"punkass.com",
"rediffmail.com",
"rmqkr.net",
"rocketmail.com",
"rogers.com",
"rr.com",
"safe-mail.net",
"sbcglobal.net",
"sharklasers.com",
"sky.com",
"sneakemail.com",
"sofort-mail.de",
"sogetthis.com",
"spam.la",
"spambob.com",
"spambob.net",
"spambob.org",
"spambog.com",
"spamex.com",
"spamgourmet.com",
"spamhole.com",
"spaminator.de",
"spammotel.com",
"spamtrail.com",
"sympatico.ca",
"talktalk.co.uk",
"telus.net",
"tiscali.co.uk",
"trash-mail.de",
"trashmail.net",
"trashymail.com",
"verizon.net",
"virgin.net",
"virginmedia.com",
"wanadoo.co.uk",
"wow.com",
"wuzup.net",
"yahoo.co.uk",
"yahoo.com",
"ygm.com",
"ymail.com",
"yopmail.com",
"zigmail.com",
"zoho.com",
Halid_Delkic
Level 3
Works for me. Kathi, thanks very much for sharing. 
Kathi_Gosche
Level 4
Glad it worked for you Jon. Enjoy.
Jon_Jagelsky
Level 2

That worked great! Thank you so much Kathi
 

Wish i had developer like that in-house 🙂 

Kathi_Gosche
Level 4

One of my developers came up with this code that has worked for me. Depending on the way your button is designed, it may or may not work for you, but you can give it a try.

Replace your old validation code with the below:

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script type="text/javascript" charset="utf-8">
var $jQ = jQuery.noConflict();
var invalidDomains =
[
"hotmail.com",
"yahoo.com",
"aol.com",
"gmail.com",
];
$jQ(document).ready(function(){
if ($jQ('.mktoButtonRow').length == 0) {
window.setTimeout(function(){
emailValidation();
}, 500);
} else {
emailValidation();
}
});
$jQ('#Email').bind('blur', function(){
if (isEmailValid()){
var $error = $jQ(this).parent().find('.mktoError');
if ($error.length > 0) {
$error.fadeOut(200, function(){
$error.remove();
$jQ('#Email').removeClass('mktoInvalid');
});
}
}
});
function emailValidation() {
var $buttonRow = $jQ('.mktoButtonRow');
var submitText = $buttonRow.find('button').html();
var $replacement = $jQ('<input id="replacementButton" type="button" class="mktoButton" value="' + submitText + '" />');
$buttonRow.hide();
var buttonRowContents = $buttonRow.html();
$span = $jQ(buttonRowContents).html('');
var $replacementRow = $jQ('<div class="mktoFormRow" />').append($span.append($replacement));
$jQ('.mktoFormRow :last').after($replacementRow);
$jQ('#replacementButton').click(function(){
console.log('debug1');
if (!isEmailValid()) {
console.log('debug2');
var $error = $jQ('#Email').parent().find('.mktoError');
if ($error.length == 0) {
$error = getError('Please provide a business or institutional email address');
$jQ('#Email').after($error);
}
$error.fadeIn(200);
$jQ('#Email').removeClass('mktoInvalid').addClass('mktoInvalid');
return;
} else {
console.log('debug3');
$jQ('.mktoButtonRow button').trigger('click');
}
});
}
function isEmailValid() {
var email = $jQ('#Email').val().toLowerCase();
for(i=0; i < invalidDomains.length; i++) {
var invalidDomain = invalidDomains[i].toLowerCase();
if (email.indexOf(invalidDomain) !== -1) {
return false;
}
    }
return true;
}
function getError(message, detail) {
var $container = $jQ('<div class="mktoError" style="right: 0px; bottom: -47px; display: none" />');
var $arrow = $jQ('<div class="mktoErrorArrowWrap"><div class="mktoErrorArrow"></div></div>');
var $errorMessage = $jQ('<div class="mktoErrorMsg" />').html(message);
if (typeof detail == 'string' && $jQ.trim(detail) != '') {
$errorMessage = $errorMessage.append($jQ('<span class="mktoErrorDetail" />').html(detail))
}
return $container.append($arrow).append($errorMessage);
}
</script>
Anonymous
Not applicable

Do you know if this code should be on the landing page template (in the Design Studio) or should it be on the landing page itself? Or does it not matter? Thank you,

--Regan

Kathi_Gosche
Level 4

I have it placed on the landing page itself. I haven't tried it in a template, but that might work fine too. If you try it, I would be interested to hear how it worked out.

Halid_Delkic
Level 3
We’re experiencing the same issue since switching over to forms 2.0.

Tried dragging/dropping the form first, followed by the JS, but the block isn’t working as it did on forms 1.0.
 
Would be interested to hear if anyone has discovered an alternative method.
Kathi_Gosche
Level 4
That's the same code I've been using with 1.0 forms and it worked great. However it doesn't seem to work at all with 2.0 forms.