-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
75 lines (64 loc) · 3 KB
/
index.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="../css/style.css">
<title>Sign-Up</title>
<script>
function validateForm(event) {
event.preventDefault();
let isValid = true;
const errorText = document.querySelector('.error-text');
errorText.innerHTML = '';
const firstName = document.querySelector('input[name="first_name"]').value.trim();
const lastName = document.querySelector('input[name="last_name"]').value.trim();
const email = document.querySelector('input[name="email"]').value.trim();
const password = document.querySelector('input[name="password"]').value.trim();
const img = document.querySelector('input[name="img"]').files[0];
if (firstName === '') {
isValid = false;
errorText.innerHTML += '<p>Firstname is required.</p>';
}
if (lastName === '') {
isValid = false;
errorText.innerHTML += '<p>Lastname is required.</p>';
}
const emailPattern = /^[^ ]+@[^ ]+\.[a-z]{2,3}$/;
if (!emailPattern.test(email)) {
isValid = false;
errorText.innerHTML += '<p>Please enter a valid email address.</p>';
}
const passwordPattern = /^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&])[A-Za-z\d@$!%*?&]{6,}$/;
if (!passwordPattern.test(password)) {
isValid = false;
errorText.innerHTML += '<p>Password must be at least 8 characters long, contain at least one uppercase letter, one lowercase letter, one number, and one special character.</p>';
}
if (isValid) {
document.querySelector('form').submit();
}
}
document.addEventListener('DOMContentLoaded', () => {
document.querySelector('form').addEventListener('submit', validateForm);
});
</script>
</head>
<body>
<div class="register">
<div class="register-img">
<img src="/components/images/kids.png" alt="">
</div>
<form action="/php/signup.php" method="post" enctype="multipart/form-data">
<h1>Register</h1>
<div class="error-text"></div>
<input type="text" name="first_name" placeholder="Firstname" required>
<input type="text" name="last_name" placeholder="LastName" required>
<input type="email" name="email" placeholder="email" required>
<input type="password" name="password" placeholder="enter password" required><br>
<input type="file" name="img" id="img" class="customfile">
<input type="submit" class="button" value="Sign-in"><br>
<p>Already a user? <a href="login.html" style="color:#0718c4;font-weight:600">Login</a></p>
</form>
</div>
</body>
</html>