Repository navigation
Expand file tree
/
Copy pathP10.html
More file actions
141 lines (126 loc) · 5.11 KB
/
Copy pathP10.html
File metadata and controls
141 lines (126 loc) · 5.11 KB
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
<html>
<head>
<title>Form Validation</title>
</head>
<body>
<h1>FORM VALIDATION</h1>
<form name="form" action="" onsubmit="return validateForm()">
<label>Name : </label>
<select name="init" id="init">
<option>Mr.</option>
<option>Mrs.</option>
<option>Ms.</option>
</select>
<input type="text" id="fname" name="fname" placeholder="Enter your Name"><br><br>
<label>Phone : </label>
<select name="num" id="num">
<option>+91</option>
<option>+966</option>
<option>+971</option>
</select>
<input type="tel" id="phone" name="phone" placeholder="Enter Mobile number"><br><br>
<label>Email : </label>
<input type="text" id="email" name="email" placeholder="Enter your email"><br><br>
<label>Gender</label>
<input type="radio" name="gender" value="Male"><label>Male</label>
<input type="radio" name="gender" value="Female"><label>Female</label>
<input type="radio" name="gender" value="Other"><label>Other</label>
<br><br>
<label>Languages Known : </label>
<input type="checkbox" name="lang" value="Malayalam">Malayalam
<input type="checkbox" name="lang" value="English">English
<input type="checkbox" name="lang" value="Hindi">Hindi
<input type="checkbox" name="lang" value="Tamil">Tamil<br><br>
<label>Password : </label>
<input type="password" id="pwd" name="pwd" placeholder="Enter Password"><br><br>
<label>Confirm Password : </label>
<input type="password" id="cpwd" name="cpwd" placeholder="Confirm Password"><br><br>
<button type="submit">Submit</button>
</form>
<script>
function validateForm()
{
var fname = document.form.fname.value.trim();
var phone = document.form.phone.value.trim();
var email = document.form.email.value.trim();
var gender = document.querySelector('input[name="gender"]:checked');
var lang = document.querySelectorAll('input[name="lang"]:checked');
var pwd = document.form.pwd.value;
var cpwd = document.form.cpwd.value;
if(fname == "")
{
alert("Enter your Name");
document.form.fname.focus();
return false;
}
else if(!/^[a-zA-Z ]+$/.test(fname))
{
alert("Enter valid Name");
document.form.fname.focus();
return false;
}
if(phone == "")
{
alert("Enter Mobile Number");
document.form.phone.focus();
return false;
}
else if(!/^[0-9]{10}$/.test(phone))
{
alert("Enter a valid 10-digit Mobile Number");
document.form.phone.focus();
return false;
}
if(email == "")
{
alert("Enter email");
document.form.email.focus();
return false;
}
else if(!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email))
{
alert("Enter a valid email");
document.form.email.focus();
return false;
}
if(gender == null)
{
alert("Select your Gender");
document.querySelector('input[name="gender"]').focus();
return false;
}
if(lang.length == 0)
{
alert("Select atleast one language");
return false;
}
if(pwd == "")
{
alert("Enter Password");
document.form.pwd.focus();
return false;
}
else if(!/^(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])(?=.*[^a-zA-Z0-9]).{8,}$/.test(pwd))
{
alert("Password must be at least 8 characters and include an uppercase letter, a lowercase letter, a number and a special character");
document.form.pwd.focus();
return false;
}
if(cpwd == "")
{
alert("Confirm your Password");
document.form.cpwd.focus();
return false;
}
else if(pwd !== cpwd)
{
alert("Passwords do not match");
document.form.cpwd.focus();
return false;
}
alert("Form Submitted Successfully");
return true;
}
</script>
</body>
</html>