Email regex JavaScript Validation | Example code

An email is a string (a subset of ASCII characters) separated into two parts by @ symbol. A “Unique_personal_id” and a domain. It can easily validate by using regex JavaScript.

reg ex – Regular + expression

First part can contains the following ASCII characters.

  • Uppercase (A-Z) and lowercase (a-z) English letters.
  • Digits (0-9).
  • Characters ! # $ % & ‘ * + – / = ? ^ _ ` { | } ~
  • Character . ( period, dot or fullstop) provided that it is not the first or last character and it will not come one after the other.

Second part

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

Example code of Email regex JavaScript

Simple complete HTML example of JavaScript code to validate an email id :-

In this example using input fields for email address and button for click. if the email id valid then it will show a Valid alert box otherwise will show invalid.

Output:

HTML Example code of Email regex JavaScript

What is Regular Expression Pattern for email id?

Answer: Here is email validation Regular Expression Pattern code:

Do comment if you have any problems, doubts, and suggestions on this topic.

Note: All JS Examples codes are tested on the Firefox browser and the Chrome browser.
OS: Windows 10
Code: HTML 5 Version


Leave a Reply

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