From 040d94087b9b496b2fc16db574357bb4c7b8d73f Mon Sep 17 00:00:00 2001 From: Chirag Date: Mon, 14 Oct 2024 22:19:01 +0530 Subject: [PATCH] Email format validation added --- SignUp/signup.js | 6 ++++++ login/login.html | 7 +++++++ 2 files changed, 13 insertions(+) diff --git a/SignUp/signup.js b/SignUp/signup.js index 95675265..a6a9ba95 100644 --- a/SignUp/signup.js +++ b/SignUp/signup.js @@ -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, diff --git a/login/login.html b/login/login.html index da164510..fa23aea0 100644 --- a/login/login.html +++ b/login/login.html @@ -83,6 +83,13 @@

Login to Your Account

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