-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathform.html
187 lines (149 loc) · 7.94 KB
/
form.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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link rel="stylesheet" href="form.css" type="text/css">
<script type="text/javascript">
function fnameValidation(){
var reg = /[A-Za-z]{2,}/ ;
var firstNameValue = document.getElementById("fname").value;
if (reg.test(firstNameValue))
{
document.getElementById("fnameFeed").style.color="green";
document.getElementById("fnameFeed").innerHTML="<strong>well done! 😍</strong>";
}
else
{
document.getElementById("fnameFeed").style.color="red";
document.getElementById("fnameFeed").innerHTML="<strong>not valid 😟</strong>";
}
}
function lnameValidation(){
var reg =/[A-Za-z]{2,}/ ;
var firstNameValue = document.getElementById("lname").value;
if (reg.test(firstNameValue))
{
document.getElementById("lnameFeed").style.color="green";
document.getElementById("lnameFeed").innerHTML="<strong>well done! 😍</strong>";
}
else
{
document.getElementById("lnameFeed").style.color="red";
document.getElementById("lnameFeed").innerHTML="<strong>not valid 😟</strong>";
}
}
function pswValidation(){
var reg = /((?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[\W]).{8,64})/g ;
var firstNameValue = document.getElementById("psw").value;
if (reg.test(firstNameValue))
{
document.getElementById("pswFeed").style.color="green";
document.getElementById("pswFeed").innerHTML="<strong>well done! 😍</strong>";
}
else
{
document.getElementById("pswFeed").style.color="red";
document.getElementById("pswFeed").innerHTML="<strong>not valid 😟</strong>";
}
}
function numValidation(){
var reg = /(\+?( |-|\.)?\d{1,2}( |-|\.)?)?(\(?\d{3}\)?|\d{3})( |-|\.)?(\d{3}( |-|\.)?\d{4})/g ;
var firstNameValue = document.getElementById("num").value;
if (reg.test(firstNameValue))
{
document.getElementById("numFeed").style.color="green";
document.getElementById("numFeed").innerHTML="<strong>well done! 😍</strong>";
}
else
{
document.getElementById("numFeed").style.color="red";
document.getElementById("numFeed").innerHTML="<strong>not valid 😟</strong>";
}
}
function dateValidation(){
var reg = /^(0?[1-9]|1[0-2])[\/](0?[1-9]|[12]\d|3[01])[\/](19|20)\d{2}$/ ;
var firstNameValue = document.getElementById("date").value;
if (reg.test(firstNameValue))
{
document.getElementById("dateFeed").style.color="green";
document.getElementById("dateFeed").innerHTML="<strong>well done! 😍</strong>";
}
else
{
document.getElementById("dateFeed").style.color="red";
document.getElementById("dateFeed").innerHTML="<strong>not valid 😟</strong>";
}
}
function emailValidation(){
var reg = /\b[\w\.-]+@[\w\.-]+\.\w{2,4}\b/ ;
var firstNameValue = document.getElementById("email").value;
if (reg.test(firstNameValue))
{
document.getElementById("emailFeed").style.color="green";
document.getElementById("emailFeed").innerHTML="<strong>well done! 😍</strong>";
}
else
{
document.getElementById("emailFeed").style.color="red";
document.getElementById("emailFeed").innerHTML="<strong>not valid 😟</strong>";
}
}
function javaScriptValidation(){
var input1=document.getElementById("fname").value;
var input2=document.getElementById("lname").value;
var input3=document.getElementById("psw").value;
var input4=document.getElementById("psw1").value;
var input5=document.getElementById("num").value;
var input6=document.getElementById("date").value;
var input7=document.getElementById("email").value;
console.log("dfgadfasf");
if(input1==""){ alert("Please fill the first name");}
else if(input2==""){ alert("Please fill the last name");}
else if(input3==""){ alert("Please fill the password name");}
else if(input4==""){ alert("Please fill the re-enter password");}
else if(input5==""){ alert("Please fill the number");}
else if(input6==""){ alert("Please fill the date");}
else if(input7==""){ alert("Please fill the email");}
else{
alert("Please conform to submit");
}
}
function psw1Validation(){
var firstNameValue = document.getElementById("psw").value;
var psw1=document.getElementById("psw1").value;
console.log(psw1,firstNameValue);
if( firstNameValue==psw1){
document.getElementById("psw1Feed").style.color="green";
document.getElementById("psw1Feed").innerHTML="<strong>correct 👍</strong>";
}
else{
document.getElementById("psw1Feed").style.color="red";
document.getElementById("psw1Feed").innerHTML="<strong>don,t match 😡</strong>";
}
}
</script>
</head>
<body>
<div class="form" >
<form action="" class="formContent" onsubmit="javaScriptValidation();">
<h1 id="heading">User information</h1>
<label for="fname">Enter your first name:</label><br>
<input type="text" id="fname" name="fname" onblur="fnameValidation();" placeholder="at least two chara.."><span id="fnameFeed"></span><br>
<label for="lname">Enter your last name:</label><br>
<input type="text" id="lname" name="lname" onblur="lnameValidation();" placeholder="at least two chara.."><span id="lnameFeed"></span><br>
<label for="psw">Enter your password:</label><br>
<input type="password" id="psw" name="password" onblur="pswValidation();"placeholder="Vishal#mau@kj456"><span id="pswFeed" ></span><br>
<input type="password" id="psw1" name="password1" onblur="psw1Validation();" placeholder="re-enter the password"><span id="psw1Feed"></span>
<label for="num">Enter your number:</label><br>
<input type="number" id="num" name="number" onblur="numValidation();" placeholder="only 10 digits"><span id="numFeed"></span><br>
<label for="date">Enter your DOB:</label><br>
<input type="date" id="date" name="date" onblur="dateValidation"><span id="dateFeed" ></span><br>
<label for="email">Enter email:</label><br>
<input type="text" id="email" name="email" onblur="emailValidation();" placeholder="[email protected]" ><span id="emailFeed" ></span><br>
<button type="submit" >submit:</button>
</form>
</div>
</body>
</html>