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

Feat: Registration Form #11

Merged
merged 1 commit into from
Jan 31, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
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
62 changes: 62 additions & 0 deletions form-validation/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Registration Form</title>
<link rel="stylesheet" href="styles.css" />
</head>
<body>
<div class="form-container">
<form id="registrationForm">
<h1>Registration Form</h1>
<div class="form-group">
<div class="form-input">
<label for="name">Name</label>
<input type="text" id="name" required />
</div>
<div class="error" id="nameError"></div>
</div>
<div class="form-group">
<div class="form-input">
<label for="email">Email</label>
<input type="email" id="email" required />
</div>
<div class="error" id="emailError"></div>
</div>
<div class="form-group">
<div class="form-input">
<label for="password">Password</label>
<input type="password" id="password" required />
</div>
<div class="error" id="passwordError"></div>
</div>
<div class="form-group">
<div class="form-input">
<label for="confirmPassword">Confirm Password</label>
<input type="password" id="confirmPassword" required />
</div>
<div class="error" id="confirmPasswordError"></div>
</div>
<div class="form-group">
<div class="form-input">
<label for="age">Age</label>
<input type="number" id="age" required min="18" max="99" />
</div>
<div class="error" id="ageError"></div>
</div>
<button type="submit" id="submitForm">Submit</button>
<div class="success" id="successMessage"></div>
</form>
</div>

<div class="modal-overlay" id="modalOverlay"></div>

<div class="modal" id="successModal">
<p>🎉 Registration Successful!</p>
<button id="closeModal">OK</button>
</div>

<script src="script.js"></script>
</body>
</html>
77 changes: 77 additions & 0 deletions form-validation/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
function clearForm() {
document.getElementById("name").value = "";
document.getElementById("email").value = "";
document.getElementById("password").value = "";
document.getElementById("confirmPassword").value = "";
document.getElementById("age").value = "";
document.querySelectorAll(".error").forEach(function (error) {
error.textContent = "";
});
}

function showModal() {
document.getElementById("successModal").style.display = "block";
document.getElementById("modalOverlay").style.display = "block";
}

function hideModal() {
document.getElementById("successModal").style.display = "none";
document.getElementById("modalOverlay").style.display = "none";
clearForm();
}

document
.getElementById("registrationForm")
.addEventListener("submit", function (event) {
event.preventDefault();
let valid = true;

document.querySelectorAll(".error").forEach(function (error) {
error.textContent = "";
});
document.getElementById("successMessage").textContent = "";

const name = document.getElementById("name").value;
if (name.length < 3) {
valid = false;
document.getElementById("nameError").textContent =
"Name must be at least 3 characters.";
}

const email = document.getElementById("email").value;
const emailPattern = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
if (!emailPattern.test(email)) {
valid = false;
document.getElementById("emailError").textContent =
"Invalid email format.";
}

const password = document.getElementById("password").value;
const passwordPattern =
/^(?=.*[0-9])(?=.*[!@#$%^&*])[A-Za-z\d!@#$%^&*]{6,}$/;
if (!passwordPattern.test(password)) {
valid = false;
document.getElementById("passwordError").textContent =
"Password must be at least 6 characters, contain a number and a special character.";
}

const confirmPassword = document.getElementById("confirmPassword").value;
if (password !== confirmPassword) {
valid = false;
document.getElementById("confirmPasswordError").textContent =
"Passwords do not match.";
}

const age = document.getElementById("age").value;
if (age < 18 || age > 99) {
valid = false;
document.getElementById("ageError").textContent =
"Age must be between 18 and 99.";
}

if (valid) {
showModal();
}
});

document.getElementById("closeModal").addEventListener("click", hideModal);
108 changes: 108 additions & 0 deletions form-validation/styles.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
body {
color: whitesmoke;
font-family: Arial, sans-serif;
background-color: whitesmoke;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
height: 100vh;
width: 100vw;
margin: 0;
padding: 0;
}

.form-container {
background: #0d1b2a;
padding: 20px;
width: 90%;
max-width: 400px;
border-radius: 10px;
box-shadow: 5px 5px 5px rgba(0, 0, 0, 0.4);
transition: transform 0.5s ease-in-out;
}

#registrationForm {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}

.form-group {
display: flex;
flex-direction: column;
width: 100%;
}

.form-input {
display: flex;
justify-content: space-between;
align-items: center;
}

input {
width: calc(60% - 20px);
padding: 10px;
margin: 5px 0;
color: #0d1b2a;
background-color: whitesmoke;
border: 1px solid whitesmoke;
border-radius: 5px;
}

button {
padding: 10px;
margin: 10px 0;
width: 20%;
max-width: 350px;
color: whitesmoke;
background-color: #0d1b2a;
border: 1px solid whitesmoke;
border-radius: 5px;
cursor: pointer;
}

button:hover {
color: #0d1b2a;
background-color: whitesmoke;
}

.error {
color: red;
font-size: 0.8rem;
margin: 0;
}

.success {
color: green;
font-size: 0.8rem;
margin: 0;
}

.modal-overlay {
display: none;
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: rgba(0, 0, 0, 0.5);
z-index: 1000;
}

.modal {
display: none;
position: fixed;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
background: #0d1b2a;
padding: 20px;
border-radius: 8px;
box-shadow: 5px 5px 5px rgba(0, 0, 0, 0.4);
text-align: center;
z-index: 1001;
width: 90%;
max-width: 300px;
}
6 changes: 5 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,15 @@

<body>
<h1>Automation Scenarios</h1>
<div id="login-and-signup">
<div id="login-and-signup" class="item">
<p>[Username: John | Password: Doe]</p>
<a href="./login/index.html">Login and Signup</a>
</div>

<div id="form-validation" class="item">
<a href="./form-validation/index.html">Form Validation</a>
</div>

<footer>
<p>Author: Muhammad Hammad Faisal</p>
<a href="https://github.com/M-Hammad-Faisal/my-automation-site">
Expand Down
6 changes: 3 additions & 3 deletions styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,19 @@ h1 {
flex-shrink: 0;
}

#login-and-signup {
.item {
text-align: center;
margin-top: 20px;
font-size: 16px;
}

#login-and-signup a {
.item a {
color: #0d1b2a;
text-decoration: none;
font-weight: bold;
}

#login-and-signup a:hover {
.item a:hover {
color: #ff6347;
}

Expand Down