diff --git a/.vscode/launch.json b/.vscode/launch.json deleted file mode 100644 index bed780b..0000000 --- a/.vscode/launch.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - // Use IntelliSense to learn about possible attributes. - // Hover to view descriptions of existing attributes. - // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 - "version": "0.2.0", - "configurations": [ - - - - ] -} \ No newline at end of file diff --git a/MAIN.js b/MAIN.js index 2d90c66..c45c3e4 100644 --- a/MAIN.js +++ b/MAIN.js @@ -42,11 +42,16 @@ const submitBtn = document.getElementById("submit-btn"); const passwordInput = document.querySelector("#password"); const retypePasswordInput = document.querySelector("#password-con"); const messageElement = document.getElementById("Message"); +const email = document.querySelector("#email"); async function isValidPassword(password) { const reg = /^(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[a-zA-Z]).{8,}$/; return reg.test(password); } +function isValidEmail(email) { + const reg = /^[^\s@]+@[^\s@]+\.[^\s@]+$/; + return reg.test(email); +} function confirmPasswordMatch() { const password = passwordInput.value; @@ -73,12 +78,27 @@ function checkPasswordMatch() { passwordInput.addEventListener("input", confirmPasswordMatch); retypePasswordInput.addEventListener("input", confirmPasswordMatch); } -checkPasswordMatch(); submitBtn.addEventListener("click", async (e) => { const isPasswordValid = await isValidPassword(passwordInput.value); const doPasswordsMatch = confirmPasswordMatch(); - if (!isPasswordValid || !doPasswordsMatch) { + if ( + !isPasswordValid || + !doPasswordsMatch || + !isValidEmail(emailInput.value) + ) { e.preventDefault(); } }); +function checkEmailValidity() { + email.addEventListener("input", (event) => { + if (!isValidEmail(email.value)) { + email.setCustomValidity("Invalid email address!"); + } else { + email.setCustomValidity(""); + } + }); +} + +checkEmailValidity(); +checkPasswordMatch(); diff --git a/index.html b/index.html index c6607dd..ff71467 100644 --- a/index.html +++ b/index.html @@ -25,7 +25,7 @@