Skip to content

Commit c683f85

Browse files
Add simple regex check for email format on Auth pag
1 parent 503197d commit c683f85

2 files changed

Lines changed: 17 additions & 2 deletions

File tree

‎app.js‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,3 +265,18 @@ if (backToTopBtn) {
265265
});
266266
}
267267
});
268+
269+
function handleAuth(event) {
270+
event.preventDefault();
271+
272+
const email = document.getElementById("email").value;
273+
274+
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
275+
276+
if (!emailRegex.test(email)) {
277+
alert("Enter a valid email address");
278+
return;
279+
}
280+
281+
window.location.href = "library.html";
282+
}

‎auth.html‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,8 @@
8585
<main>
8686
<div class="auth-container">
8787
<h2 style="margin-bottom: 2rem;">Welcome Back</h2>
88-
<form onsubmit="event.preventDefault(); window.location.href='library.html';">
89-
<input type="email" class="auth-input" placeholder="Email Address" required>
88+
<form onsubmit="handleAuth(event)">
89+
<input type="email" id="email" class="auth-input" placeholder="Email Address" required>
9090
<input type="password" class="auth-input" placeholder="Password" required>
9191
<button type="submit" class="auth-btn">Sign In</button>
9292
</form>

0 commit comments

Comments
 (0)