Skip to content

Commit 9b0d0ef

Browse files
Merge pull request #631 from Mahendra2611/fix/email-validation
Fix : email validation function
2 parents f678b36 + 80ffee2 commit 9b0d0ef

File tree

1 file changed

+48
-11
lines changed

1 file changed

+48
-11
lines changed

signin.html

Lines changed: 48 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -50,26 +50,63 @@ <h1>Welcome to <span class="brand">SkillWise</span></h1>
5050
</div>
5151
<p class="suggestion">
5252
<small>Use special characters and numbers for a strong password</small>
53+
5354
</p> -->
54-
<button type="submit" class="signin-btn">Sign In</button>
55+
56+
<button type="submit" class="signin-btn" id="submit">Sign In</button>
57+
5558
<p class="signup-link">Don't have an account? <a href="./signup.html">Sign up here</a></p>
5659
</form>
5760
</div>
5861
</div>
5962
<script src="https://kit.fontawesome.com/a076d05399.js"></script>
60-
<script >
61-
const togglePassword = document.querySelector("#togglePassword");
62-
const passwordInput = document.querySelector("#password");
63-
64-
togglePassword.addEventListener("click", function () {
65-
const type = passwordInput.getAttribute("type") === "password" ? "text": "password";
66-
passwordInput.setAttribute("type", type);
6763

68-
this.classList.toggle("fa-eye-slash");
69-
this.classList.toggle("fa-eye");
70-
});
64+
<script>
65+
const togglePassword = document.querySelector("#togglePassword");
66+
const passwordInput = document.querySelector("#password");
67+
const submitBtn = document.querySelector("#submit");
68+
const emailInput = document.querySelector("#email");
69+
70+
togglePassword.addEventListener("click", function () {
71+
const type = passwordInput.getAttribute("type") === "password" ? "text" : "password";
72+
passwordInput.setAttribute("type", type);
73+
74+
this.classList.toggle("fa-eye-slash");
75+
this.classList.toggle("fa-eye");
76+
});
77+
78+
79+
80+
submitBtn.addEventListener("click", (e) => {
81+
e.preventDefault();
82+
83+
const email = emailInput.value;
84+
const emailError = document.getElementById("emailError");
85+
86+
87+
const emailPattern = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,6}$/;
88+
89+
if (!emailPattern.test(email)) {
90+
91+
if (!emailError) {
92+
const errorMsg = document.createElement("p");
93+
errorMsg.id = "emailError";
94+
errorMsg.style.color = "red";
95+
errorMsg.textContent = "Email is incorrect. Please enter a valid email address.";
96+
emailInput.parentElement.appendChild(errorMsg);
97+
}
98+
} else {
99+
100+
if (emailError) {
101+
emailError.remove();
102+
}
103+
104+
e.target.closest("form").submit();
105+
}
106+
});
71107

72108
</script>
109+
73110

74111
</body>
75112
</html>

0 commit comments

Comments
 (0)