Comparing passwords in Twitter Bootstrap for validation purposes

After creating a simple form with Twitter Bootstrap, I managed to incorporate some validation as well.

<form class="form-signin">            
<input type="email" class="input-block-level" placeholder="Email address" required="">
<input type="password" class="input-block-level" placeholder="Password" required="">
<input type="password" class="input-block-level" placeholder="Confirm Password" required="">
<button class="btn btn-large btn-primary" type="submit">Sign in</button>
</form>

In my search for examples, I haven't come across anyone implementing password comparison validation. I'm curious if there's a way to achieve this within Twitter Bootstrap without resorting to using jQuery Validator. Can CSS be utilized for password comparison validation instead of relying on the form.validate() script?

Thank you

Answer №1

To implement form validation using CSS without relying on the jQuery validate plugin, you can follow this approach:

$('form').on('submit',function(){
   if($('#password').val() !== $('#confirm-password').val()){
       alert('Passwords do not match');
       return false;
   }
   return true;
});

Sample HTML Form

<form class="form-validate">
    <input type="email" class="input-block-level" placeholder="Email Address" required>
    <input id="password" type="password" class="input-block-level" placeholder="Password" required>
    <input id="confirm-password" type="password" class="input-block-level" placeholder="Confirm Password" required>
    <button class="btn btn-primary" type="submit">Submit</button>
</form>

Answer №2

Using HTML:

<input type="password" class="input-block-level" placeholder="Password" required="" id="psd">
<input type="password" class="input-block-level" placeholder="ConfirmPassword" required="" id="confirmPsd">

An id has been included for easier identification.

With JS:

$('button').on ('click', function () {
if ($('#confirmPsd').val() === $('#psd').val()) {
  alert("Passwords match");
  return true;
}
else {
  alert("Passwords do not match");
 return false;
}
})

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

How to Fix the Issue of CSS Font Face Path Not Working in Your Express Application

My current font files are stored in the public/fonts/ directory. The CSS files can be found in public/css/. Despite trying various path and css adjustments, I am unable to successfully load the fonts... @font-face {font-family: trend_sans_oneregular; ...

Tooltips in Bootstrap are not functional when used on pages other than the initial one in datatables

I have multiple data tables in development where the cells of certain columns contain Bootstrap tooltips. To achieve this, I am utilizing: The Bootstrap framework Datatables My issue arises when using Datatables with multiple pages. Upon document readin ...

Issues with Cordova and JQuery ajax functionality not operating as expected

I am facing an issue with implementing AJAX functionality in my Cordova app (CLI 6.3.1) on Visual Studio 2017. It works fine on the emulator, but I encounter a connection error when installing it on a mobile phone. I have already included CSP as shown bel ...

The dropdown list in angularjs is failing to populate with options

For populating a dropdownlist using angularjs, I attempted the following: var app = angular.module('App', []); app.controller('UserSelection', function ($scope, $location) { var User = this; User.onSelectChange = function () { i ...

Trouble activating jQuery functions alongside Stripe Elements

My form allows users to choose a payment method. If they select Credit Card, a Stripe Elements form is displayed where they can input CC/EXP/ZIP data. After clicking submit, the form should pass validation using jQuery Validate and then proceed to acquire ...

Using $window.print() in angularjs results in the print preview displaying an empty page

Encountering a strange issue where using $window.print in angularjs results in only the date, page name, page number, and url appearing on the printed page. The rest of the content is missing even though the original page has plenty of it. I suspect the p ...

Keep the entire table in place as the user scrolls

I'm trying to create a sticky table that moves while scrolling the page. I currently have two tables, one after another. However, when I scroll the page, only the first table moves about 10px and then stops. My tables don't move at all. Can anyon ...

Is there a way to delete added information using a trigger that has been inserted through ajax?

I created a function in jQuery and Ajax to add information from a separate PHP file to another file. Let's name the destination file "Homepage" and the file with the data "Template". Here is the function I used: var box = $('#infoPageContainer& ...

Verifying whether the field's value is null or empty

Is the following code snippet a reliable method for verifying if the value of a field is not null? if($('#person_data[document_type]').value() != 'NULL'){} Alternatively, are there more effective approaches to achieve this? ...

Regular expression in asp.net to prevent blank spaces is important to maintain data integrity

My application cannot handle more than one blank space, as it will cause a crash. Additionally, the user should be limited to entering a maximum of 25 characters. What regular expression can I use to enforce these rules? <asp:RegularExpressionValidator ...

Arranging Content with Bootstrap Columns

I am trying to organize my content into three sections as follows: A - main content of page B - very important content (must be visible without scrolling) C - less important content. The current layout I have is like this: ----- |A|B| |A|C| ----- Howe ...

What is the reason for nesting divs within each other?

Can anyone help me troubleshoot this Django template code? I have noticed that the main-card-faq div is being rendered inside the main-card div even though it's clearly outside. Any thoughts on what might be causing this issue? {% extends 'base.h ...

The route you are trying to access is currently unavailable

I've successfully developed a web app, and now I need to replicate the same HTML page with a slightly different controller. Despite my attempts to utilize ngRoute, it's not functioning as expected, and I'm uncertain if my route setup will yi ...

Animation using CSS keyframes for simultaneous manipulation of various properties

I am facing a challenge with animating both the bottom and left properties of an object inside a container div simultaneously. How can I make it move diagonally? Despite using keyframes, the following code does not seem to achieve this effect: #containe ...

Using ASP, JQuery, and Ajax to validate a list by comparing queries in a SQL process has been

I am facing a challenge with running multiple SQL procedures from a list using a start button. I need to execute each process one by one and update the list once each procedure is completed. Can someone please assist me? I have been struggling with this fo ...

Patiently anticipating the completion of a jQuery animation

I am currently working on some jQuery code that handles toggling containers and buttons. The specific snippet of code I am focused on is the following: var id = $(this).data('id'); if ($('#container').is(':visible')) { $( ...

What is the best way to incorporate two banners on the Magento homepage alongside my flexslider?

I recently made the switch from using a camera.js slider on my website to a Flexslider. The reason for this change was that I couldn't make the camera.js slider clickable, and I wanted to eliminate the 'Click here' button. However, now that ...

Tips for positioning the footer in HTML and CSS

footer { background-color: #000000 } .footer-nav { list-style: none; } .footer-nav li { display: inline-block; margin: 15px; font-weight: 400; font-size: 80% } .social { list-style: none; } .social li { display ...

Connect a button to a function in the controller and transmit data from the view to the controller in the Model-View-

Having an issue with jQuery AJAX and binding a button to a controller action. I've set it up like this, but it's not functioning as expected. @model InventoryTest.MyModel @using (Html.BeginForm(new { id = "itemTypeForm" })) { <input type ...

Arranging arrays in a MySQL gallery using PHP for optimal sorting

I've been attempting to organize my images from the database in a grid list format like this: ... I'm feeling stuck and unsure of what changes to make in my code. I really need some assistance, as I'm working on setting up an online store. ...