2. Validate an Email address is very important.
This validation can be performed in many
computer languages but today we are going
to Validate Email with JavaScript.
3. What is JavaScript ?
Javascript is a scripting computer language
and its abbreviation is JS. It is used to
develop complex web applications However
it is always used with CSS and HTML. It is
different from the Java computer language.
4. Why Validate Email Address
In today’s world, most of the important
communication is done through Email
addresses. Collecting email addresses is not
only important but it becomes essential
when it comes to Email Marketing.
Therefore validating the email address
5. Structure of Email Address
Consider this email address as a sample
ContactUs@EmailConcern.com. It is a valid email address. Now it
consists of 3 parts
Before @ :: It consists of the name of the email address. This part
consists of letters (capital as well as small), numbers, and special
characters.
After @ :: It consists of a domain name so here you can use (capital as
well as small), numbers, and special characters.
After dot :: It defines the type of the domain like com, org, etc. In this
part, only letters (capital as well as small), numbers, and dot(optional)
can appear.
6. Validate Email with JavaScript
To validate the Email with Javascript I use the following code.
<!DOCTYPE html>
<html>
<body>
<h1>Validate Email with JavaScript</h1>
<input id="EmailAddress">
<button type="button" onclick="VALIDATE_EMAIL_ADDRESS()">Submit</button>
<h2 id="Result" style="color: Green;"></h2>
<script>
function VALIDATE_EMAIL_ADDRESS() {
var email;
email = document.getElementById("EmailAddress").value;
var reg = /^([A-Za-z0-9_-.])+@([A-Za-z0-9_-.])+.([A-Za-z]{2,4})$/;
8. To test the above mention code I used
W3School JavaScript online editor. In this
editor just paste the code into the editor and
press the Run button.
9.
10.
11. Conclusion
In order to collect valid email addresses, this
validation is mandatory. You cannot skip this
step. It not only makes things easy for you but
also ensures data integrity.