Skip to content

Commit 4e6faf0

Browse files
authored
updating email Validator (#1045)
* updating email Validator * updating Email Validator * update emailvalidator
1 parent 4ea62ca commit 4e6faf0

File tree

3 files changed

+71
-38
lines changed

3 files changed

+71
-38
lines changed

Public/EmailValidator.html

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,25 @@
55
<meta http-equiv="X-UA-Compatible" content="IE=edge">
66
<meta name="viewport" content="width=device-width, initial-scale=1.0">
77
<link rel="stylesheet" href="../assets/css/EmailValidator.css">
8+
89
<title>Email Validator</title>
10+
911
</head>
1012
<body>
11-
<form action="#">
12-
Email <input type="text" name="name" id="name"><br>
13-
<button id="submit"> Submit </button>
13+
<div class="container">
14+
<h2> Email Validator
15+
<hr>
16+
</h2>
17+
<form name="myForm" onsubmit="ValidateEmail(document.myForm.Email)">
18+
<p class="EmailId">
19+
<label for="email">Email Id:</label>
20+
</p>
21+
<input type="text" id="email" name="Email" placeholder="[email protected]">
22+
<button id="submit" class="btn">Submit</button>
1423
</form>
24+
</div>
1525
</body>
1626
<script src="../assets/Js/EmailValidator.js"></script>
27+
1728
</html>
29+

assets/Js/EmailValidator.js

Lines changed: 17 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,21 @@
1-
let nameinform = document.getElementById('name');
2-
let number = document.getElementById('number');
3-
let password = document.getElementById('password');
1+
let nameinform = document.getElementById('email');
42
let button = document.getElementById('submit');
5-
6-
function submit()
7-
{
8-
if(nameinform.value.includes("@") && nameinform.value.includes("."))
9-
{
10-
if(nameinform.value.indexOf("@")>0 && nameinform.value.indexOf(".")>nameinform.value.indexOf("@") && nameinform.value.indexOf(".")!=nameinform.value.length)
11-
{
12-
alert("Successful Registration");
13-
}
14-
else
15-
{
16-
alert("Please Provide Correct Email Address");
17-
}
18-
}
19-
else
20-
{
21-
alert("Please Provide Correct Email Address");
22-
}
23-
3+
function ValidateEmail(inputText) {
4+
var data = inputText.value;
5+
var atSign = data.indexOf("@");
6+
var dotSign = data.indexOf(".");
7+
if (atSign<1 ) {
8+
alert("Invalid @ position");
9+
return false;
10+
}
11+
else if (dotSign<atSign+2 || dotSign+2>=data.length){
12+
alert("Invalid . position");
13+
return false;
14+
}
15+
else{
16+
alert("Your Email Id is correct");
17+
return true;
18+
}
2419
}
25-
button.addEventListener('click',submit);
2620

2721

assets/css/EmailValidator.css

Lines changed: 39 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,46 @@
1-
body
2-
{
3-
background-color: pink;
1+
body {
2+
display: flex;
3+
justify-content: center;
4+
background-color: teal;
45
}
56

6-
form
7-
{
8-
margin: 10%;
7+
.container {
8+
background-color: white;
9+
margin-top: 160px;
10+
width: 560px;
11+
height: 300px;
12+
text-align: center;
13+
border-left: 15px solid coral;
14+
border-radius: 5px;
15+
16+
}
17+
h2 {
18+
font-family: Verdana, Geneva, Tahoma, sans-serif;
19+
font-size: 24px;
920
}
1021

11-
form input
12-
{
13-
margin: 4%;
22+
.EmailId {
23+
font-size: 22px;
24+
font-family: Cambria, Cochin, Georgia, Times, 'Times New Roman', serif;
25+
margin-top: 34px;
1426
}
1527

16-
button
17-
{
18-
padding: 2%;
28+
#email {
29+
height: 30px;
30+
width: 245px;
31+
font-family: cursive;
32+
}
33+
.btn {
34+
margin-top: 34px;
35+
height: 38px;
36+
width: 100px;
37+
border-radius: 5px;
38+
border: 1px solid black;
39+
background-color: teal;
40+
color: white;
41+
font-size: 15px;
42+
}
43+
.btn:hover {
44+
background-color: coral;
45+
cursor: pointer;
1946
}

0 commit comments

Comments
 (0)