Skip to content

Instantly share code, notes, and snippets.

@dillansimmons
Last active June 11, 2020 19:47
Show Gist options
  • Save dillansimmons/7a36bb82fc17ce4e07d6e3cc49a7cfc0 to your computer and use it in GitHub Desktop.
Save dillansimmons/7a36bb82fc17ce4e07d6e3cc49a7cfc0 to your computer and use it in GitHub Desktop.
Restrict free email addresses: Marketo
// Taken from http://developers.marketo.com/blog/restrict-free-email-domains-on-form-fill-out/
// Prepared by Ian Taylor and Murtza Manzur on 9/9/2014 - Modified Dillan Simmons 8/15/17
(function (){
// Please include the email domains you would like to block in this list
var invalidDomains = ["@gmail.","@yahoo.","@hotmail.","@live.","@aol.","@outlook.","@test."];
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;
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment