Skip to content

Instantly share code, notes, and snippets.

@timmatheson
Last active January 14, 2022 05:33
Show Gist options
  • Save timmatheson/17c5a1de11a9ddfaf4846aa62719278c to your computer and use it in GitHub Desktop.
Save timmatheson/17c5a1de11a9ddfaf4846aa62719278c to your computer and use it in GitHub Desktop.
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