Validate email address using JavaScript

An email address is a string separated into two parts by '@' symbol. A "personal-part" and a domain-name, that is personal-part@domain-name. The length of the personal-part may be up to 64 characters long and domain-name may be up to 253 characters . The personal-part contains the following ASCII characters.
  1. Uppercase: (A-Z) and lowercase (a-z) English letters.
  2. Digits: (0-9).
  3. Characters: ! # $ % & ' * + - / = ? ^ _ ` { | } ~
  4. Character: . ( period, dot or fullstop) provided that it is not the first or last character and it will not come one after the other.

The domain name [for example: com, org, net, in, us, info] part contains letters, digits, hyphens, and dots.

Example of valid email id

mysite@example.com Keep in mind that one should not rely only upon JavaScript email validation because JavaScript can easily be disabled.
validate email address using javascript/jquery

Regular Expression

A regular expression is an object that describes a pattern of characters. The following JavaScript shows how to validate an email address using Regular Expression .
function validateEmail(inText){ const re = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/; var email=document.getElementById(inText).value; if(re.test(String(email).toLowerCase())) { alert("Email is valid : " + email); } else { alert("Email is not valid : " + email); } }
Full Source | JavaScript
<html> <head> <title>Email Validation</title> <script type="text/javascript"> function validateEmail(inText){ const re = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/; var email=document.getElementById(inText).value; if(re.test(String(email).toLowerCase())) { alert("Email is valid : " + email); } else { alert("Email is not valid : " + email); } } </script> </head> <body> <h1>Validate Email address using JavaScript.</h1> <b>Enter Email Address: </b> <input type="text" id="textIn1"/><br><br> <input type="button" id="btnSum" value="Validate" onClick="validateEmail('textIn1')"/> </body> </html>