Javascript email validation w3schools

According to W3Schools, here is a JavaScript email validation function:

function validateEmail(email) {
  var emailReg = /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/;
  if (emailReg.test(email)) {
    return true;
  } else {
    return false;
  }
}

This function uses a regular expression to check if the input string matches the format of an email address. Here's a breakdown of the regular expression:

You can use this function like this:

var email = "[email protected]";
if (validateEmail(email)) {
  alert("Email is valid");
} else {
  alert("Email is not valid");
}

Note that this is a basic email validation and may not cover all possible valid email formats. For more advanced email validation, you may want to use a more complex regular expression or a dedicated email validation library.