Created
January 14, 2022 05:09
-
-
Save timmatheson/9479b1dbdcdd6c78254cb7110add209d 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"} | |
]; | |
let suggestionSelector = "suggestion"; | |
document.addEventListener("DOMContentLoaded", () => { | |
document.getElementById(suggestionSelector).innerHTML = ""; // reset the message | |
let forms = document.querySelector("form"); | |
forms.addEventListener("submit", (e) => { | |
if(document.getElementById(suggestionSelector).innerHTML !== ""){ | |
document.getElementById(suggestionSelector).innerHTML = ""; | |
}else{ | |
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){ | |
document.getElementById(suggestionSelector).innerHTML = `Did you mean ${suggestion}?`; | |
break; | |
} | |
}) | |
} | |
}); | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment