-
Notifications
You must be signed in to change notification settings - Fork 0
/
signup.html
55 lines (49 loc) · 1.73 KB
/
signup.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
<!DOCTYPE html>
<html>
<head>
<title>Form Page</title>
<style>
.error {
color: red;
}
</style>
</head>
<body>
<h1>Registration Form</h1>
<form id="registrationForm" onsubmit="validateForm(event)">
<label for="name">Name:</label>
<input type="text" id="name" name="name" required>
<span id="nameError" class="error"></span>
<br><br>
<label for="password">Password:</label>
<input type="password" id="password" name="password" required>
<span id="passwordError" class="error"></span>
<br><br>
<input type="submit" value="Submit">
</form>
<script>
function validateForm(event) {
event.preventDefault(); // Prevent form submission
// Get form values
var name = document.getElementById("name").value;
var password = document.getElementById("password").value;
// Reset error messages
document.getElementById("nameError").innerHTML = "";
document.getElementById("passwordError").innerHTML = "";
// Validate name length
if (name.length < 3) {
document.getElementById("nameError").innerHTML = "Name must be greater than 2 letters";
return;
}
// Validate password strength
var passwordRegex = /^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&])[A-Za-z\d@$!%*?&]{8,}$/;
if (!passwordRegex.test(password)) {
document.getElementById("passwordError").innerHTML = "Password must include at least one lowercase letter, one uppercase letter, one number, and one special symbol (@$!%*?&)";
return;
}
// If form is valid, proceed with form submission
document.getElementById("registrationForm").submit();
}
</script>
</body>
</html>