Create a Password Validator using Tailwind CSS Last Updated : 28 Apr, 2025 Summarize Comments Improve Suggest changes Share Like Article Like Report Passwords must be strong so that hackers can not hack them easily. The following example shows how to check the password strength of the user input password in Tailwind CSS and jQuery. We will use the validator module to achieve this functionality. We will call the isStrongPassword function and pass the conditions as its parameters. PrerequisitesHTMLTailwind CSSjQueryApproachHTML Structure: Defines a password input field and a list of password strength criteria.Tailwind CSS Styling: Applies styles for layout, input fields, buttons, and icons using Tailwind CSS utility classes.Password Visibility Toggle: Allows users to toggle password visibility with the eye icon button.Password Strength Validation: Uses jQuery to listen for input changes in the password field and validates the password against criteria such as minimum length, presence of uppercase and lowercase letters, and symbols.Feedback Display: Updates the UI dynamically to display feedback on whether the password meets the required criteria and indicates its strength as either strong or weak.Example: This example shows the implementation of the above-explained approach. HTML <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Password Strength Checker</title> <!-- Tailwind CSS --> <link href= "https://cdn.jsdelivr.net/npm/[email protected]/dist/tailwind.min.css" rel="stylesheet"> <!-- Font Awesome --> <link href= "https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/all.min.css" rel="stylesheet"> </head> <body class="bg-gray-100 flex justify-center items-center h-screen"> <div class="bg-white shadow-md rounded-md p-4 w-full md:w-1/2"> <h2 class="text-xl font-bold mb-4 text-center"> Checking Password Strength in JavaScript </h2> <div class="mb-4"> <label for="password" class="block"> Enter Password: </label> <div class="flex items-center"> <input type="password" class="border border-gray-300 form-input flex-1" id="password"> <button class="ml-2 px-3 py-2 border border-gray-300 rounded-md bg-white text-gray-600 " type="button" id="togglePassword"> <i class="fas fa-eye"></i> </button> </div> </div> <div class="mb-4"> <ul> <li id="minLength"><i class="fas fa-times text-red-500"></i> Minimum 8 characters</li> <li id="uppercase"><i class="fas fa-times text-red-500"></i> At least one uppercase letter</li> <li id="lowercase"><i class="fas fa-times text-red-500"></i> At least one lowercase letter</li> <li id="symbol"><i class="fas fa-times text-red-500"></i> At least one symbol (@$!%*?&)</li> </ul> </div> <span id="errorMessage" class="font-semibold text-red-500"></span> </div> <!-- jQuery --> <script src= "https://code.jquery.com/jquery-3.6.0.min.js"> </script> <!-- Font Awesome --> <script src= "https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/js/all.min.js"> </script> <script> // Function to toggle password visibility $('#togglePassword').click(function () { const passwordInput = $('#password'); const icon = $(this).find('i'); if (passwordInput.attr('type') === 'password') { passwordInput.attr('type', 'text'); icon.removeClass('fa-eye').addClass('fa-eye-slash'); } else { passwordInput.attr('type', 'password'); icon.removeClass('fa-eye-slash').addClass('fa-eye'); } }); $('#password').on('input', function () { const password = $(this).val(); const strongPasswordRegex = /^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&])[A-Za-z\d@$!%*?&]{8,}$/; const errorMessage = $('#errorMessage'); $('#minLength').html(password.length >= 8 ? '<i class="fas fa-check text-green-500"></i> Minimum 8 characters' : '<i class="fas fa-times text-red-500"></i> Minimum 8 characters'); $('#uppercase').html(/[A-Z]/.test(password) ? '<i class="fas fa-check text-green-500"></i> At least one uppercase letter' : '<i class="fas fa-times text-red-500"></i> At least one uppercase letter'); $('#lowercase').html(/[a-z]/.test(password) ? '<i class="fas fa-check text-green-500"></i> At least one lowercase letter' : '<i class="fas fa-times text-red-500"></i> At least one lowercase letter'); $('#symbol').html(/[@$!%*?&]/.test(password) ? '<i class="fas fa-check text-green-500"></i> At least one symbol (@$!%*?&)' : '<i class="fas fa-times text-red-500"></i> At least one symbol (@$!%*?&)'); if (strongPasswordRegex.test(password)) { errorMessage.text('Strong Password').removeClass('text-red-500') .addClass('text-green-500'); } else { errorMessage.text('Weak Password').removeClass('text-green-500') .addClass('text-red-500'); } }); </script> </body> </html> Output: Comment More infoAdvertise with us G geekwriter2024 Follow Improve Article Tags : Project Web Technologies JQuery Dev Scripter Dev Scripter 2024 +1 More Similar Reads JavaScript Tutorial JavaScript is a programming language used to create dynamic content for websites. It is a lightweight, cross-platform, and single-threaded programming language. It's an interpreted language that executes code line by line, providing more flexibility.JavaScript on Client Side: On the client side, Jav 11 min read Web Development Web development is the process of creating, building, and maintaining websites and web applications. It involves everything from web design to programming and database management. Web development is generally divided into three core areas: Frontend Development, Backend Development, and Full Stack De 5 min read React Interview Questions and Answers React is an efficient, flexible, and open-source JavaScript library that allows developers to create simple, fast, and scalable web applications. Jordan Walke, a software engineer who was working for Facebook, created React. Developers with a JavaScript background can easily develop web applications 15+ min read React Tutorial React is a powerful JavaScript library for building fast, scalable front-end applications. Created by Facebook, it's known for its component-based structure, single-page applications (SPAs), and virtual DOM,enabling efficient UI updates and a seamless user experience.Note: The latest stable version 7 min read JavaScript Interview Questions and Answers JavaScript is the most used programming language for developing websites, web servers, mobile applications, and many other platforms. In Both Front-end and Back-end Interviews, JavaScript was asked, and its difficulty depends upon the on your profile and company. Here, we compiled 70+ JS Interview q 15+ min read Domain Name System (DNS) DNS is a hierarchical and distributed naming system that translates domain names into IP addresses. When you type a domain name like www.geeksforgeeks.org into your browser, DNS ensures that the request reaches the correct server by resolving the domain to its corresponding IP address.Without DNS, w 8 min read HTML Interview Questions and Answers HTML (HyperText Markup Language) is the foundational language for creating web pages and web applications. Whether you're a fresher or an experienced professional, preparing for an HTML interview requires a solid understanding of both basic and advanced concepts. Below is a curated list of 50+ HTML 14 min read NodeJS Interview Questions and Answers NodeJS is one of the most popular runtime environments, known for its efficiency, scalability, and ability to handle asynchronous operations. It is built on Chromeâs V8 JavaScript engine for executing JavaScript code outside of a browser. It is extensively used by top companies such as LinkedIn, Net 15+ min read Sequence Diagrams - Unified Modeling Language (UML) A Sequence Diagram is a key component of Unified Modeling Language (UML) used to visualize the interaction between objects in a sequential order. It focuses on how objects communicate with each other over time, making it an essential tool for modeling dynamic behavior in a system. Sequence diagrams 11 min read Web Development Technologies Web development refers to building, creating, and maintaining websites. It includes aspects such as web design, web publishing, web programming, and database management. It is the creation of an application that works over the internet, i.e., websites.To better understand the foundation of web devel 7 min read Like