Limit Email Domains on Form Submission | Community
Skip to main content
Jon_Jagelsky
Level 2
February 3, 2014
Solved

Limit Email Domains on Form Submission

  • February 3, 2014
  • 20 replies
  • 6183 views
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?
This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by Kathi_Gosche

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>

20 replies

Kathi_Gosche
Level 4
February 5, 2014
I have run into this issue as well. In fact, that's why I came into the Community today.
Level 10
February 6, 2014
First drag and drop the form to the landing page draft and then add the JS to the HTML box, which is to be dropped on the landing page. The JS needs to be added in the landing page draft in the HTML box of the editor.
Kathi_Gosche
Level 4
February 6, 2014
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.
haliddelkic
Level 3
February 7, 2014
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
Kathi_GoscheAccepted solution
Level 4
February 7, 2014

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>
June 22, 2016

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
June 22, 2016

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.

Jon_Jagelsky
Level 2
February 7, 2014

That worked great! Thank you so much Kathi
 

Wish i had developer like that in-house :) 

Kathi_Gosche
Level 4
February 7, 2014
Glad it worked for you Jon. Enjoy.
haliddelkic
Level 3
February 14, 2014
Works for me. Kathi, thanks very much for sharing. 
March 18, 2014
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",
Jon_Jagelsky
Level 2
March 28, 2014
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. });