-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest.html
125 lines (117 loc) · 4.2 KB
/
test.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
<!DOCTYPE html>
<html>
<head>
<title>Form with Validation</title>
<style>
body {
font-family: Arial, sans-serif;
margin: 0;
padding: 20px;
background-color: #f4f4f4;
}
h1 {
color: #333;
text-align: center;
}
form {
background-color: #fff;
padding: 20px;
border-radius: 8px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
max-width: 500px;
margin: 20px auto;
}
input[type="text"], input[type="tel"], input[type="number"], input[type="email"], input[type="password"], textarea {
width: 100%;
padding: 10px;
margin: 6px 0 20px 0;
display: inline-block;
border: 1px solid #ccc;
border-radius: 4px;
box-sizing: border-box;
}
input[type="submit"] {
width: 100%;
background-color: #4CAF50;
color: white;
padding: 14px 20px;
margin: 8px 0;
border: none;
border-radius: 4px;
cursor: pointer;
}
input[type="submit"]:hover {
background-color: #45a049;
}
label {
color: #555;
}
</style>
<script>
function validateform() {
let name = document.forms["sform"]["name"].value;
let number = document.forms["sform"]["number"].value;
let gender = document.forms["sform"]["gender"].value;
let zip = document.forms["sform"]["zip"].value;
let email = document.forms["sform"]["email"].value;
let password = document.forms["sform"]["password"].value;
var nameReg = /\d/;
var emailReg = /^[\w-\.]+@gmail\.com$/;
var passwordReg = /^(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{8,}$/;
if (nameReg.test(name)) {
alert("Name has number!");
return false;
}
if (!emailReg.test(email)) {
alert("Email must be a Gmail address!");
return false;
}
if (!passwordReg.test(password)) {
alert("Password must contain at least 8 characters, including 1 uppercase, 1 lowercase, and 1 number.");
return false;
}
if (number.length != 5) {
alert("Too small :(");
return false;
}
if (!gender) {
alert("Amara detected!?");
return false;
}
if (zip.length != 6) {
alert("America nahi hai :/");
return false;
}
window.location.href = "thankyou.html";
return false;
}
</script>
</head>
<body>
<h1>User Details Form</h1>
<br>
<form name="sform" onsubmit="return validateform()">
<label for="name">Name: </label>
<input name="name" id="name" type="text" required>
<br><br>
<label for="number">Number: </label>
<input name="number" id="number" required type="tel">
<br><br>
Gender: Male <input type="radio" name="gender" value="Male"> Female <input type="radio" name="gender" value="Female">
<br><br>
<label for="Address">Address: </label><br>
<textarea name="Address" required></textarea>
<br><br>
<label for="zip">Pin Code: </label>
<input name="zip" id="zip" required type="number">
<br><br>
<label for="email">Email: </label>
<input name="email" id="email" required type="email">
<br><br>
<label for="password">Password: </label>
<input name="password" id="password" required type="password" pattern="(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{8,}">
<br><br>
<input type="submit" value="Submit">
</form>
</body>
</html>