-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsignup.txt
63 lines (55 loc) · 2.17 KB
/
signup.txt
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Signup</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="form-container">
<h2>Create an Account</h2>
<form id="signup-form">
<label for="name">Full Name</label>
<input type="text" id="name" placeholder="Enter your name" required>
<label for="email">Email/Mobile</label>
<input type="text" id="email" placeholder="Enter email or mobile number" required>
<label for="password">Password</label>
<input type="password" id="password" placeholder="Enter password" required>
<button type="button" onclick="signUp()">Sign Up</button>
</form>
<p>Already have an account? <a href="login.html">Login here</a>.</p>
</div>
<script>
async function signUp() {
const name = document.getElementById('name').value;
const email = document.getElementById('email').value;
const password = document.getElementById('password').value;
if (!validateEmail(email)) {
alert("Invalid email format!");
return;
}
try {
const response = await fetch('http://localhost:5000/signup', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ name, email, password })
});
const result = await response.json();
if (response.ok) {
alert("Account created successfully! Please login.");
window.location.href = 'login.html';
} else {
alert(result.error);
}
} catch (error) {
console.error(error);
}
}
function validateEmail(email) {
const re = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
return re.test(email);
}
</script>
</body>
</html>