Email Validation in Javascript

Email ID is a very important part of a user account. When an application invites the user to create accounts or allow users to subscribe to a newsletter, they ask for an email ID. Email ID is the initial medium of formal communication, so this is mandatory that the email is received should be in a valid format.

Here we are going to explain how to do Email Validation in JavaScript?

An Email is a string with a very simple structure. There are two parts :

  1. unique_id
  2. Domain Name

These two parts are separated by @. 

Suppose is an email where the first part interviewsortout is Unique User ID at the domain.

The length of the unique_id part may be up to 64 characters long and domain name may be up to 253 characters.

The first part of an email may have the following characters :

  • May contain Alphabets either in upper case or in lower case.
  • Any Digits 
  • Special character except @  
  • a dot(.) can not be the first and last character of uique_id

The second part is the domain name. So we can have .com, .in, .info, .net, .au etc type of domain. 

Have a look at some valid email addresses:



Now Have a look on Invalid Email Address : 

  • @not present : []
  • Top Level Domain can not be started with dot ( . ) : [ ]
  • [ No character before @ ]
  •  invalid top level domain   [exampleuser123@gmail.b]
  • an email can not start with “.” [ ]
  • double dots are not allowed []


To do email validation in javascript we will use Regular Expression to match that the given email address matches the criteria of a valid domain.


Regular Expression for email validation in JavaScript:




A complete Solution of Email Validation in Javascript :

Spread the love

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.