From 9a38ad172e86ea4c538b2f2998f0f2ae304e79a4 Mon Sep 17 00:00:00 2001 From: S4NKALP Date: Tue, 3 Jun 2025 13:59:02 +0545 Subject: [PATCH] refactor(login): remove pattern and title attributes from username input, add form validation on submit --- templates/login/login.html | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/templates/login/login.html b/templates/login/login.html index 6f27f7a..f020410 100644 --- a/templates/login/login.html +++ b/templates/login/login.html @@ -237,7 +237,7 @@ {% csrf_token %}
- +
@@ -272,6 +272,23 @@ icon.classList.toggle('fa-eye-slash'); }); }); + + document.addEventListener('DOMContentLoaded', function() { + const form = document.querySelector('form'); + const usernameInput = document.getElementById('username'); + + form.addEventListener('submit', function(event) { + const value = usernameInput.value.trim(); + const emailPattern = /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/; + const phonePattern = /^\d{10}$/; + + if (!emailPattern.test(value) && !phonePattern.test(value)) { + event.preventDefault(); + alert('Please enter a valid email address or a 10-digit phone number.'); + usernameInput.focus(); + } + }); + });