Forked from MurtzaM/preventNonBusinessEmailSubmission.js
Created
June 22, 2018 13:22
-
-
Save zagriyen/404032940c09b59eabb7dc9d88933379 to your computer and use it in GitHub Desktop.
This script will prevent Marketo form submission if a user enters a non-business email (Gmail, Hotmail, etc.)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment