WEBLEB
Home
Editor
Login
Pro
English
English
Français
Español
Português
Deutsch
Italiano
हिंदी
HTML
CSS
JS
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.
.input-group-text { cursor: pointer; }
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'); } });
Validating your code, please wait...
HTML
CSS
JS
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.
.input-group-text { cursor: pointer; }
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'); } });