Check email id is valid or not

A simple yet important task!

To check if an email ID is valid or not, you can use a regular expression (regex) to validate the format of the email address. Here's a simple regex pattern that you can use:

^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$

Let's break down what this regex pattern checks:

You can use this regex pattern in your programming language of choice to validate an email ID. Here's an example in JavaScript:

function isValidEmail(email) {
  const regex = /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/;
  return regex.test(email);
}

const email = "[email protected]";
if (isValidEmail(email)) {
  console.log("Email is valid");
} else {
  console.log("Email is not valid");
}

Keep in mind that this is a basic validation and may not catch all invalid email addresses. For example, it won't check if the email address actually exists or if the domain is valid. If you need more advanced email validation, you may want to consider using a dedicated email validation library or service.