Can you try below code, I am sure you can get what you are looking for.
function validateEmail(email) {
// Regular expression to validate email format
var regex = /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/;
if (regex.test(email)) {
return true;
} else {
return false;
}
}
var userEmail = "user@example.com";
var isValid = validateEmail(userEmail);
if (isValid) {
console.log("Email is valid.");
} else {
console.log("Email is not valid.");
}
Thanks