title: JQuery validate field number length depends
body: <p>I'm using <a href="http://jqueryvalidation.org/" rel="nofollow noreferrer">JQuery Validation Plugin</a> and i want change the <code>minlength</code> and <code>maxlength</code> of my field (zip code) that depends if country is equal to PT (Portugal) or not.</p>
  
  <p>But in validation the result are always:</p>
  
  <p><img src="https://i.stack.imgur.com/I53bf.png" alt="enter image description here"></p>
  
  <p>Anyone knows what is my problem?</p>
  
  <p><strong>HTML:</strong></p>
  
  <pre><code>&lt;body&gt;
  &lt;form id="myform"&gt;
  &lt;label for="field"&gt;Required, minimum 3(Other) or 9(PT): &lt;/label&gt;
      &lt;input type="text" class="left" id="field" name="field"/&gt;
  &lt;br/&gt;
  &lt;select class="form-control" id="country" name="country"&gt;
      &lt;option value="0"&gt;-- Choose Country --&lt;/option&gt;
      &lt;option value="BE"&gt;Belgium &lt;/option&gt;
      &lt;option value="BR"&gt;Brazil &lt;/option&gt;
      &lt;option value="ES"&gt;Spain &lt;/option&gt;
      &lt;option value="FR"&gt;France &lt;/option&gt;
      &lt;option value="NL"&gt;Dutch &lt;/option&gt;
      &lt;option selected="selected" value="PT"&gt;Portugal &lt;/option&gt;       
      &lt;/select&gt;    
      &lt;br/&gt;
      &lt;input type="submit" value="Validate!"/&gt;
  &lt;/form&gt;
  &lt;/body&gt;
  </code></pre>
  
  <p><strong>JQuery:</strong></p>
  
  <pre><code>jQuery.validator.setDefaults({
      debug: true,
      success: "valid"
  });
  
  $("#myform").validate({
      rules: {
          field: {
              required: true,
              number: {
                  depends: function () {
                      return !($('select[name="country"]').val() != 'PT');
                  }
              },
              minlength: {
                  depends: function () {
  
                      var country = $('select[name="country"]').val();
  
                      if (country == 'PT') {
                          return 9;
                      } else {
                          return 3;
                      }
                  }
              },
              maxlength: {
                  depends: function () {
                      var country = $('select[name="country"]').val();
                      if (country == 'PT') {
                          return 9;
                      } else {
                          return 50;
                      }
                  }
              }
          }
      }
  });
  </code></pre>
  
  <p><strong><a href="http://jsfiddle.net/Y2H9d/22/" rel="nofollow noreferrer">JSFIDDLE</a></strong></p>