How to validate only working Email in JavaScript? Actually, I want only working email excluding (@gmail.com, @outlook.com, @hotmail.com, @yahoo.com etc). I want only working emails like abc@stack.com etc.
This code is also working!
let text = "abc@hotmail.com";
let domain = text.substring(text.lastIndexOf("@"));
if(domain == "@gmail.com" || domain == "@yahoo.com" || domain == "@hotmail.com" || domain == "@outlook.com"){
console.error("Wrong format")
}else{
console.log("working email")
}
One way is to get the domain part from the email, and check it against the list of personal email domains:
const workingEmailValidator = email =>
!['gmail', 'hotmail', 'yahoo', 'outlook'].includes(email.split('@')[1].split('.')[0])
console.log(workingEmailValidator('xyz@sss.com'))
I use my own function after checking if email is valid then you can check if it is work email or not :
const notAllowed = ["gmail.com", "email.com", "yahoo.com", "outlook.com"];
function check(email) {
const lastPortion = email.split("@")[1].toLowerCase();
if (notAllowed.includes(lastPortion)) {
console.log("Please enter work email");
return false;
}
return true;
}
check("abc@paiman.com");
check("abc@gmail.com.com");