Last active
January 14, 2022 05:33
-
-
Save timmatheson/17c5a1de11a9ddfaf4846aa62719278c to your computer and use it in GitHub Desktop.
This file contains 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
let domainMispellings = [ | |
{"gmial.com" : "gmail.com"}, | |
{"gmale.com" : "gmail.com"}, | |
{"gmmail.com" : "gmail.com"}, | |
{"gmaill.com" : "gmail.com"}, | |
{"gmaik.com" : "gmail.com"}, | |
{"gnail.com" : "gmail.com"}, | |
{"yagoo.com" : "yahoo.com"}, | |
{"yahooo.com" : "yahoo.com"}, | |
{"yaho.com" : "yahoo.com"}, | |
{"hotmial.com" : "hotmail.com"}, | |
{"hormail.com" : "hotmail.com"}, | |
{"hotnail.com" : "hotmail.com"}, | |
{"msm.com" : "msn.com"} | |
]; | |
document.addEventListener("DOMContentLoaded", () => { | |
// bind to the form and check the email | |
let forms = document.querySelector("form"); | |
forms.addEventListener("submit", (e) => { | |
let suggestionWrapper = document.getElementById("suggestion"); | |
if(suggestionWrapper.innerHTML === ""){ | |
e.preventDefault(); | |
e.stopPropagation(); | |
let email = forms.querySelector("input[type=email]"); | |
let emailValue = email.value.split("@")[1]; | |
domainMispellings.forEach((hash, i) => { | |
let suggestion = hash[emailValue]; | |
if(suggestion !== undefined){ | |
suggestionWrapper.innerHTML = `Did you mean ${suggestion}?`; | |
} | |
}) | |
}else{ | |
suggestionWrapper.innerHTML = ""; | |
} | |
}); | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment