function activateValidation(element, button) { element.onkeyup = function () { // Clear email warning var fieldValue = element.value; var elementParent = element.parentNode.parentNode.parentNode.parentNode; // if you want below email field, uncomment line below // var elementParent = element.parentNode; var emailAlert = null; for (var i = 0; i < elementParent.childNodes.length; i++) { if (elementParent.childNodes[i].className == "business_email_alert") { emailAlert = elementParent.childNodes[i]; emailAlert.remove(); } } // Validate email domain if (fieldValue.includes("@") && fieldValue.includes(".")) { for (i = 0; i < newEmailsArray.length; i++) { if (fieldValue.indexOf(newEmailsArray[i]) >= 0) { button.setAttribute("disabled", "disabled"); node = document.createElement("span"); node.setAttribute("class", "business_email_alert"); node.setAttribute("style", "color: red; font-size: 12px;"); var textnode = document.createTextNode( "You have provided a personal email address, " + fieldValue + ". Please provide us with your company email. Thank you." ); node.appendChild(textnode); element.parentElement.parentElement.parentElement.parentElement.appendChild(node); // if you want below email field, uncomment line below // element.parentElement.appendChild(node); return; } } } // Enable button back if domain is not found button.removeAttribute("disabled"); button.disabled = false; console.log('function running // domain not found'); } } newEmailsArray=["@gmail.com","@yahoo.com","@hotmail.com","@aol.com","@freemail.com","@freemail.ca","@freemail.trade","@freemail.hu","@hotmail.co.uk","@hotmail.fr","@msn.com","@yahoo.fr","@wanadoo.fr","@orange.fr","@comcast.net","@yahoo.co.uk","@yahoo.co.in","@live.com","@rediffmail.com","@free.fr","@gmx.de","@web.de","@yandex.ru","@ymail.com","@libero.it","@outlook.com","@uol.com.br","@bol.com.br","@mail.ru","@cox.net","@hotmail.it","@sbcglobal.net","@sfr.fr","@live.fr","@verizon.net","@live.co.uk","@googlemail.com","@yahoo.es","@ig.com.br","@live.nl","@bigpond.com","@terra.com.br","@yahoo.it","@neuf.fr","@yahoo.de","@alice.it","@rocketmail.com","@att.net","@laposte.net","@facebook.com","@bellsouth.net","@yahoo.in","@hotmail.es","@icloud.com","@zipmail.com.br","@gmx.com","@gmx.us","@mail.com","@aim.com","@zoho.com","@protonmail.com","@protonmail.ch","@asia.com","@berlin.com","@comic.com","@consultant.com","@contractor.net","@dodo.com.au","@doglover.com","@doramail.com","@dr.com","@dublin.com","@dutchmail.com","@elvisfan.com","@email.com","@emailaccount.com","@everymail.net","@excite.com","@execs.com","@exemail.com.au","@f-m.fm","@financier.com","@fireman.net","@flashmail.com","@galaxyhit.com","@icqmail.com","@iinet.net.au","@inbox.com","@innocent.com","@inorbit.com","@lycos.com","@me.com","@netzero.net","@reddif.com","@safe-mail.net","@vfemail.net","@yandex.com","@zilladog.com"]; window.onload = function() { activateValidation(document.querySelector('._form_7 #email'), document.querySelector('#_form_7_submit')); activateValidation(document.querySelector('._form_5 #email'), document.querySelector('#_form_5_submit')); activateValidation(document.querySelector('._form_11 #email'), document.querySelector('#_form_11_submit')); activateValidation(document.querySelector('._form_9 #email'), document.querySelector('#_form_9_submit')); activateValidation(document.querySelector('._form_3 #email'), document.querySelector('#_form_3_submit')); activateValidation(document.querySelector('._form_15 #email'), document.querySelector('#_form_15_submit')); activateValidation(document.querySelector('._form_19 #email'), document.querySelector('#_form_19_submit')); activateValidation(document.querySelector('._form_1 #email'), document.querySelector('#_form_1_submit')); }