Skip to content

Commit

Permalink
Email format validation added
Browse files Browse the repository at this point in the history
  • Loading branch information
Cgarg9 committed Oct 14, 2024
1 parent 83823ee commit 040d940
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
6 changes: 6 additions & 0 deletions SignUp/signup.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ document.addEventListener("DOMContentLoaded", () => {
alert("Every field is required");
return;
}

const emailPattern = /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/;
if (!emailPattern.test(email)) {
alert("Please enter a valid email address.");
return; // Stop the function if the email is not in the right format
}

const userdata = {
name,
Expand Down
7 changes: 7 additions & 0 deletions login/login.html
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,13 @@ <h1>Login to Your Account</h1>

const email = document.querySelector("#gmail").value;
const password = document.querySelector("#password").value;

const emailPattern = /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/;
if (!emailPattern.test(email)) {
alert("Please enter a valid email address.");
return; // Stop the function if email is not in the right format
}

const userData = {
email,
password
Expand Down

0 comments on commit 040d940

Please sign in to comment.