title: jquery enable and disable button on key press
body: <p>I have credit card field and i want to disable the pay button, if the length of the field is &lt; 15 while key press.   </p>
  
  <p>I have written the blank field validation, but how do i disable the button, if credit card length is &lt; 15.</p>
  
  <h2>html</h2>
  
  <pre><code>&lt;form id="creditcaredFrm"&gt;
      &lt;input name="cardnum" type="text" placeholder="Card Number" class="textbox iconmastercard required cc-number"&gt;
       &lt;input type="text" class="cc-number"&gt;
        -- --------- --------
        -- ------- ----- ----
  
  &lt;/form&gt;
  </code></pre>
  
  <h2>jquery</h2>
  
  <pre><code> activatePayButton('creditcaredFrm');
  function activatePayButton(formId){
        $form = $('#'+formId);     
        $form.find(':input').on('change keyup blur', function(event) { // monitor all inputs for changes                                              
        var disable = false;
        $form.find("input[type!='hidden']").each(function(i, el) { // test all inputs for values
          if ($(this).hasClass('required') &amp;&amp; $.trim(el.value) === '') {
             disable = true; // disable submit if any of them are still blank
          }                                 
        });                             
        if(disable == true){               
            $form.find('#submitBtn').addClass('disableClick');
          } else{
            $form.find('#submitBtn').removeClass('disableClick');
          }
        });                    
       }
  </code></pre>