-2

I want to show user if the text entered match with another text box value

So i have written a jQuery function to check weather if entered value matched with the existing textbox value

$('#password, #confirm_password').on('keyup', function() {
  if ($('#password').val() == $('#confirm_password').val()) {
    $('#message').html('Matching').css('color', 'green');
  } else
    $('#message').html('Not Matching').css('color', 'red');
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<label>
  text1 :
  <input name="password" id="password" type="text" value="ABC" />
</label>
<br>
<label>
  text2:
  <input type="text" name="confirm_password" id="confirm_password" /> 
</label>
<div id="message"></div>

I want the jquery to accept match even user entered without case sensitive matching

connexo
  • 53,704
  • 14
  • 91
  • 128
NaFi
  • 81
  • 1
  • 13

1 Answers1

0

Convert both the values to lower case and then match.

  $('#password, #confirm_password').on('keyup', function() {
      if ($('#password').val().toLowerCase() == $('#confirm_password').val().toLowerCase()) {
        $('#message').html('Matching').css('color', 'green');
      } else
        $('#message').html('Not Matching').css('color', 'red');
    });
fiveelements
  • 3,649
  • 1
  • 17
  • 16