-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsignup.html
60 lines (55 loc) · 2.07 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
56
57
58
59
60
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Sign Up</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="container">
<form class="signup-form" onsubmit="return validateForm()">
<h2>Sign Up</h2>
<div class="form-group">
<input type="text" id="username" placeholder="Username" required>
</div>
<div class="form-group">
<input type="text" id="fullname" placeholder="Full Name" required>
</div>
<div class="form-group">
<input type="email" id="email" placeholder="Email" required>
</div>
<div class="form-group">
<input type="password" id="password" placeholder="Password" required>
</div>
<button type="submit">Sign Up</button>
<p class="error-message" id="error-message"></p>
</form>
<p>Already have an account? <a href="login.html">Login here</a></p>
</div>
<script>
function validateForm() {
var username = document.getElementById('username').value;
var fullName = document.getElementById('fullname').value;
var email = document.getElementById('email').value;
var password = document.getElementById('password').value;
var errorMessage = document.getElementById('error-message');
var emailFormat = /^\S+@\S+\.\S+$/;
var passwordFormat = /^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&])[A-Za-z\d@$!%*?&]{8,}$/;
if (!username || !fullName || !email || !password) {
errorMessage.textContent = 'Please fill in all fields.';
return false;
}
if (!email.match(emailFormat)) {
errorMessage.textContent = 'Please enter a valid email address.';
return false;
}
if (!password.match(passwordFormat)) {
errorMessage.textContent = 'Password should be at least 8 characters long and contain at least one uppercase letter, one lowercase letter, one number, and one special character.';
return false;
}
return true;
}
</script>
</body>
</html>