-
Notifications
You must be signed in to change notification settings - Fork 161
/
script.js
29 lines (25 loc) · 1.03 KB
/
script.js
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
// Validation for sign-up form
document.getElementById("signUpForm").addEventListener("submit", function(event) {
var username = document.getElementById("signUpUsername").value;
var email = document.getElementById("signUpEmail").value;
var password = document.getElementById("signUpPassword").value;
// Basic email validation
if (!isValidEmail(email)) {
document.getElementById("signUpError").innerText = "Invalid email address";
event.preventDefault(); // Prevent form submission
return false;
}
// Basic password validation
if (password.length < 6) {
document.getElementById("signUpError").innerText = "Password must be at least 6 characters long";
event.preventDefault(); // Prevent form submission
return false;
}
// If both email and password are valid, allow form submission
return true;
});
// Function to validate email format
function isValidEmail(email) {
var emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
return emailRegex.test(email);
}