Firstly, as indicated in the comments, check the letter with a regular expression, and then check whether this letter is in the right domain.
function validateEmail(email) {
var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
if(re.test(email)){
if(email.indexOf("@thedomain.com", email.length - "@thedomain.com".length) !== -1){
console.log("VALID");
}
}
}
source
share