Untitled
unknown
plain_text
11 days ago
2.4 kB
2
Indexable
Never
// Carousel Functionality let currentSlide = 0; const slides = document.querySelectorAll(".slide"); function showSlide(slideIndex) { slides.forEach((slide, index) => { slide.style.display = (index === slideIndex) ? "block" : "none"; }); } function nextSlide() { currentSlide = (currentSlide + 1) % slides.length; showSlide(currentSlide); } function prevSlide() { currentSlide = (currentSlide - 1 + slides.length) % slides.length; showSlide(currentSlide); } // Initialize the first slide showSlide(currentSlide); // Custom Validation for Registration Form document.addEventListener('DOMContentLoaded', function () { const registrationForm = document.getElementById('registrationForm'); if (registrationForm) { registrationForm.addEventListener('submit', function (e) { e.preventDefault(); const username = document.getElementById('username').value.trim(); const email = document.getElementById('email').value.trim(); const password = document.getElementById('password').value.trim(); const errorMessage = document.getElementById('error-message'); let valid = true; // Username validation (at least 3 characters, alphanumeric) const usernameRegex = /^[A-Za-z0-9]{3,}$/; if (!usernameRegex.test(username)) { valid = false; errorMessage.textContent = "Username must be at least 3 characters long and alphanumeric."; } // Email validation (basic pattern) const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/; if (!emailRegex.test(email)) { valid = false; errorMessage.textContent = "Please enter a valid email address."; } // Password validation (at least 6 characters) if (password.length < 6) { valid = false; errorMessage.textContent = "Password must be at least 6 characters long."; } if (valid) { errorMessage.textContent = "Registration successful!"; // Here, you could send the form data to the server, e.g., via AJAX alert("Form submitted successfully!"); registrationForm.reset(); } }); } });
Leave a Comment