-
Notifications
You must be signed in to change notification settings - Fork 1
/
email_validation.html
53 lines (45 loc) · 1.52 KB
/
email_validation.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title> Email Validation JavaScript </title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div>
<h3> Email Validation Check </h3>
<form id="form" action="#">
<div class="inputBox">
<input type="text" name="" id="email" placeholder="Enter Enter Address" onkeydown="validation()">
<span id="text"></span>
</div>
</form>
</div>
<script type="text/javascript">
function validation() {
var form = document.getElementById("form");
var email = document.getElementById("email").value;
var text = document.getElementById("text");
var pattern = /^[^ ]+@[^ ]+\.[a-z]{2,3}$/;
if (email.match(pattern)) {
form.classList.add("valid");
form.classList.remove("invalid");
text.innerHTML = "Valid Email Address";
text.style.color = "#ooffoo";
}
else {
form.classList.remove("valid");
form.classList.add("invalid");
text.innerHTML = "Please Enter Vaild Email Address";
text.style.color = "#ff0000";
}
if (email == "") {
form.classList.remove("valid");
form.classList.remove("invalid");
text.innerHTML = "";
text.style.color = "#ooffoo";
}
}
</script>
</body>
</html>