In web page we often ask email from user and also try to check if that email is valid or not ? Here we will see how to check whether a email valid or not using Javascript.

In this case we will use Regular expression.

Solution

 var regexPattern = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;
 return regexPattern.test(inputText);

In this regexPattern we are checking if the email full fill it's structure or not .

Example of valid email id

Example of invalid email id

Hope this is helpful.