Validate Email with JavaScript.pdf

EmailConcern 52 views 11 slides Apr 19, 2022
Slide 1
Slide 1 of 11
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11

About This Presentation

It is about Validate Email with JavaScript. Email validation is mandatory for email marketing and any sort of advertisement.


Slide Content

Validate Email with JavaScript

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.

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.

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
becomesmandatory

Structure of Email Address
Consider this email address as a sample
[email protected]. 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.
Ifanyofthestructuresisviolatedtheemailaddressbecomesinvalid

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})$/;

Validate Email with JavaScript
if (reg.test(EmailAddress.value) == false)
{
document.getElementById("Result").style.color = "red";
document.getElementById("Result").innerHTML ="Invalid EMail Address "+ email;
return false;
}
else
{
document.getElementById("Result").style.color = "Green";
document.getElementById("Result").innerHTML ="Valid Email Address"+email;
}
return true;
}
</script>

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.

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.