-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdemo2.html
142 lines (119 loc) · 4.4 KB
/
demo2.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link href="https://fonts.googleapis.com/css2?family=Baloo+2:wght@500&family=Baloo+Bhai+2:wght@500&display=swap"
rel="stylesheet">
<style>
.container input {
width: 270px;
height: 20px;
margin-top: 1px;
margin-bottom: 9px;
}
form {
padding-left: 20px;
}
.formerror {
color: red;
padding-top: 2px;
}
#but {
color: white;
background-color: #2F58CD;
width: 280px;
border-radius: 3px;
border: none;
height: 35px;
font-family: 'Baloo 2', cursive;
margin-top: 27px;
}
.container {
border: 2px solid rgb(233, 229, 229);
background-color: whitesmoke;
height: 600px;
width: 320px;
margin-left: auto;
margin-right: auto;
margin-top: 60px;
border-radius: 8px;
font-family: 'Baloo 2', cursive;
}
h2 {
font-family: 'Baloo 2', cursive;
text-align: center;
}
</style>
</head>
<body>
<div class="container">
<h2>Registration</h2>
<form aciton="/myaction.php" name="myForm" onsubmit="return validateForm()" method="post">
<div class="formdesign" id="name">
First Name: <input type="text" name="fname" required><b><span class="formerror"> </span></b>
</div>
<div class="formdesign" id="lname">
Last Name: <input type="text" name="lname" required><b><span class="formerror"> </span></b>
</div>
<div class="formdesign" id="email">
Email: <input type="email" name="femail" required><b><span class="formerror"> </span></b>
</div>
<div class="formdesign" id="phone">
Phone: <input type="phone" name="fphone" required><b><span class="formerror"></span></b>
</div>
<div class="formdesign" id="pass">
Password: <input type="password" name="fpass" required><b><span class="formerror"></span></b>
</div>
<div class="formdesign" id="address">
Address<input type="text" name="address" required><b><span class="formerror"></span></b>
</div>
<input id="but" type="submit" value="Register Now">
</form>
</div>
</body>
<script>
function clearErrors() {
errors = document.getElementsByClassName('formerror');
for (let item of errors) {
item.innerHTML = "";
}
}
function seterror(id, error) {
element = document.getElementById(id);
element.getElementsByClassName('formerror')[0].innerHTML = error;
element.getElementsByClassName('formerror')[0].style.fontSize = "12px";
element.getElementsByClassName('formerror')[0].style.paddingTop = "3px";
}
function validateForm() {
var returnval = true;
clearErrors();
var name = document.forms['myForm']["fname"].value;
var letters = /^[A-Za-z]+$/;
var uppercaseRegex = /[A-Z]/;
var specialCharRegex = /[!@#$%^&*()_+\-=\[\]{};':"\\|,.<>\/?]/;
var digitRegex = /\d/;
if (name.length < 5) {
seterror("name", "*Length of name is too short");
returnval = false;
}
if (name == letters) {
seterror("name", "*Name should contains only alphabet");
returnval = false;
}
var phone = document.forms['myForm']["fphone"].value;
if (phone.length != 10) {
seterror("phone", "*Phone number should be of 10 digits!");
returnval = false;
}
var password = document.forms['myForm']["fpass"].value;
if (password.length < 8 && password.search(uppercaseRegex) && password.search(specialCharRegex) && password.search(digitRegex)) {
seterror("pass", "*Password should be atleast 8 characters long and contain atleast one uppercase,special symbol and digit");
returnval = false;
}
return returnval;
}
</script>
</html>