-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathform_validation.html
74 lines (64 loc) · 2.09 KB
/
form_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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
<html>
<head>
<title>Form Validation</title>
<script type="text/javascript">
function val()
{
var f = document.myform;
var n = f.name;
if (n.value == "") {
alert("Please enter your name");
}
if (f.pass.value != f.cpass.value) {
alert("Password does not match");
}
if (f.pass.value.length <= 3) {
alert("Password should be atleast 4 characters long");
}
var m = f.mobno.value;
if (m.length != 10 || isNaN(m)) {
alert("Please enter mobile number correctly");
}
if (!f.c1.checked) {
alert("Please tick the checkbox");
}
if (f.city.selectedIndex < 1) {
alert("Please select the city");
}
var e = f.email;
var atpos = e.value.indexOf("@");
if (e.value == "" || atpos < 1) {
alert("Enter your Email ID ");
}
var dot = e.lastIndexOf('.');
if ((dot - atpos) >= 2)
{
alert("Incorrect Email Id");
}
}
</script>
</head>
<body>
<form name="myform" method="post" onsubmit="val()">
Name: <input name="name">
<br>
Password: <input type="password" name="pass">
<br>
Confirm Password: <input type="password" name="cpass">
<br>
Email ID: <input name="email">
<br>
Mobile Number: <input name="mobno" maxlength="10">
<br>
<input type="checkbox" name="c1" value="c1"> Please tick the checkbox
<br>
City: <select name="city">
<option>Select</option>
<option value="mumbai">Mumbai</option>
<option value="thane">Thane</option>
</select>
<br>
<input type="submit">
</form>
</body>
</html>