title: Validate password and confirm password fields using bootstrap validator
body: <p>I have stuck with adding and removing the bootstrap validator class through Jquery. I am adding validation if div is visible and remove if div is hidden. Here is my try:</p>
  <pre><code>&lt;!--hidden form field--&gt;
  &lt;div class=&quot;form-group&quot;&gt;
      &lt;a href=&quot;javascript:validateField();&quot; class=&quot;theme-color accountFormToggleBtn display-block&quot;&gt;click here to change your password&lt;/a&gt;
  
      &lt;div class=&quot;accountFormToggle display-none&quot; id=&quot;passwordForm&quot;&gt; 
        &lt;div class=&quot;col-md-5&quot;&gt;
          &lt;label for=&quot;password&quot;&gt;Password&lt;/label&gt;
          &lt;input type='password' id=&quot;password&quot; placeholder=&quot;Password&quot; name='pass' class=&quot;form-control&quot;  value='' data-bv-excluded=&quot;false&quot; required&gt;
        &lt;/div&gt;
  
        &lt;div class=&quot;col-md-5 col-md-offset-1&quot;&gt;
          &lt;label for=&quot;exampleInputEmail1&quot;&gt;Confirm password&lt;/label&gt;
          &lt;input type='password' id=&quot;password2&quot; placeholder=&quot;Confirm password&quot; name='password2' class=&quot;form-control&quot; value='' data-bv-excluded=&quot;false&quot; data-match=&quot;#password&quot; required&gt; 
        &lt;/div&gt;
      &lt;/div&gt; 
  &lt;/div&gt;
  </code></pre>
  <p>JS Code:</p>
  <pre><code>function validateField() {
     
      if($('#passwordForm').is(':visible')) {  
          $(&quot;#password&quot;).attr('data-bv-excluded',true);   
          $(&quot;#password2&quot;).attr('data-bv-excluded',true);
      } else {
          $(&quot;#password&quot;).attr('data-bv-excluded',false);   
          $(&quot;#password2&quot;).attr('data-bv-excluded',false);
      }
  }
  </code></pre>
  <p>Validation is working if div gets visible or hidden. But confirm password is not matching data with the password field.</p>
  <p>Please help me with how I can match the password and confirm password fields as per the visibility of div?</p>