WEBLEB
Home
Editor
Accedi
Pro
Italiano
English
Français
Español
Português
Deutsch
Italiano
हिंदी
Un codice di smartfunction263
759
Metehan
Apri nell'Editor
Pubblica il Tuo Codice
Consigliato
15 October 2024
Barra di navigazione blu
22 June 2025
Esempio di modulo di accesso HTML
21 April 2025
Un codice di Metehan
HTML
Copy
Bootstrap 5 Password Toggle with Validation
Add User
Add User
Add User
All star(*) marked fields are mandatory
First Name
*
First Name is required.
Last Name
*
Last Name is required.
Username
*
Username is required.
Email
*
Please enter a valid email address.
Contact
*
+91
Please enter a valid 10-digit contact number.
Password
*
Password must be at least 8 characters long.
Role
*
Select Role
Admin
Editor
Viewer
Please select a role.
CSS
Copy
@import url('https://fonts.googleapis.com/css2?family=Roboto:wght@300;400;700&display=swap'); * { margin: 0; padding: 0; box-sizing: border-box; font-family: 'Roboto', sans-serif; } body { display: flex; justify-content: center; align-items: center; min-height: 100vh; background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); background-attachment: fixed; } .login-container { width: 100%; max-width: 380px; background-color: white; border-radius: 20px; box-shadow: 0 20px 50px rgba(0,0,0,0.2); padding: 40px; text-align: center; position: relative; overflow: hidden; margin: 20px; } .login-container::before { content: ''; position: absolute; top: -50%; left: -50%; width: 200%; height: 200%; background: linear-gradient(45deg, transparent, #5d3fd3, transparent); animation: rotate 4s linear infinite; z-index: 1; } .login-container::after { content: ''; position: absolute; top: 0; left: 0; right: 0; bottom: 0; background: white; margin: 5px; border-radius: 15px; z-index: 2; } .login-content { position: relative; z-index: 3; } .login-logo { font-size: 2.5rem; font-weight: bold; color: #5d3fd3; margin-bottom: 30px; } .input-group { margin-bottom: 20px; } .input-group input { width: 100%; padding: 12px; border: 2px solid #e0e0e0; border-radius: 10px; outline: none; transition: all 0.3s ease; } .input-group input:focus { border-color: #5d3fd3; box-shadow: 0 0 10px rgba(93,63,211,0.2); } .login-btn { width: 100%; padding: 12px; background-color: #5d3fd3; color: white; border: none; border-radius: 10px; cursor: pointer; transition: all 0.3s ease; } .login-btn:hover { background-color: #4a32a8; transform: translateY(-3px); } .error-message { color: #ff4757; margin-bottom: 15px; display: none; } .social-login { display: flex; justify-content: space-between; margin-top: 20px; } .social-btn { width: 45%; padding: 10px; border-radius: 8px; border: none; cursor: pointer; font-weight: bold; transition: transform 0.3s ease; } .social-btn:hover { transform: scale(1.05); } .google-btn { background-color: #fff; border: 1px solid #ddd; color: #333; } .facebook-btn { background-color: #3b5998; color: white; } @media (max-width: 480px) { .login-container { width: 90%; padding: 20px; } .login-logo { font-size: 2rem; } .social-login { flex-direction: column; } .social-btn { width: 100%; margin-bottom: 10px; } } @keyframes rotate { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } }
JS
Copy
function togglePassword() { const passwordField = document.getElementById("userPassword"); const toggleEye = document.getElementById("toggleEye"); if (passwordField.type === "password") { passwordField.type = "text"; toggleEye.classList.remove("fa-eye"); toggleEye.classList.add("fa-eye-slash"); } else { passwordField.type = "password"; toggleEye.classList.remove("fa-eye-slash"); toggleEye.classList.add("fa-eye"); } } // Custom form validation (function () { 'use strict' const forms = document.querySelectorAll('.needs-validation') Array.prototype.slice.call(forms) .forEach(function (form) { form.addEventListener('submit', function (event) { if (!form.checkValidity()) { event.preventDefault() event.stopPropagation() } form.classList.add('was-validated') }, false) }) })(); // Form validation using Bootstrap 5 document.getElementById('addUserForm').addEventListener('submit', function (event) { event.preventDefault(); // Prevent form submission // Check if form is valid if (!this.checkValidity()) { event.stopPropagation(); this.classList.add('was-validated'); } else { alert('User added successfully!'); // You can add code here to send data to the server or further process the form this.reset(); // Reset the form this.classList.remove('was-validated'); } });