Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

confirm_password_added and social_handles_added #345

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
confirm_password_added
anmolraj-029 committed Jun 10, 2024
commit 05cf0f9d4cffd2fc7755a29ab3f399d191f467c6
53 changes: 47 additions & 6 deletions script.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,64 @@
// 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);
// }

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;
var confirmPassword = document.getElementById("signUpConfirmPassword").value;

var errorMessage = "";

// Basic email validation
if (!isValidEmail(email)) {
document.getElementById("signUpError").innerText = "Invalid email address";
event.preventDefault(); // Prevent form submission
return false;
errorMessage = "Invalid email address";
}

// Basic password validation
if (password.length < 6) {
document.getElementById("signUpError").innerText = "Password must be at least 6 characters long";
else if (password.length < 6) {
errorMessage = "Password must be at least 6 characters long";
}

// Confirm password validation
else if (password !== confirmPassword) {
errorMessage = "Passwords do not match";
}

// Display error message if there is any
if (errorMessage) {
document.getElementById("signUpError").innerText = errorMessage;
event.preventDefault(); // Prevent form submission
return false;
}

// If both email and password are valid, allow form submission
// If all validations pass, allow form submission
return true;
});

@@ -27,3 +67,4 @@ function isValidEmail(email) {
var emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
return emailRegex.test(email);
}

1 change: 1 addition & 0 deletions signup.html
Original file line number Diff line number Diff line change
@@ -14,6 +14,7 @@ <h2>Sign Up</h2>
<input type="text" id="signUpUsername" placeholder="Username" required>
<input type="email" id="signUpEmail" placeholder="Email" required>
<input type="password" id="signUpPassword" placeholder="Password" required>
<input type="password" id="signUpConfirmPassword" placeholder="Confirm Password" required />
<button type="submit">Sign Up</button>
</form>
<p id="signUpError" class="error-message"></p>