jQuery Validation plugin: dependency-callback not working...

jQuery Validation plugin: dependency-callback not working...

I'm trying to create a US zip code (5-digit numeric) validation for a text field that applies only when "United States" is selected from a drop-down. Here's a quick example


the dependency-callback is working for the "required" rule -- if I select "other" in this example, the zip field is not required. However, the 5-digit requirement persists. In what documentation I can find, it seems like this should work, and be the cleanest solution.

I also tried creating a validation method for the 5 digit requirement and using the same callback function as for the "required" rule, in place of the "true" when that method is added to the zip name. This didn't work ether.

This issue is hinted at, but I'm having a hard time finding an applicable example or answer. Any help or advice, would be much appreciated. 

The form:
  1. <form id="addressForm">
  2. <input type="text" name="zip" id="zipField" class="required"><br>
  3. <select name="country" id="country" class="required">
  4. <option value="US">United States</option>
  5. <option value="other">Other</option>
  6. </select>
  7. <input type="submit">
  8. </form>
The javascript:
  1. $(document).ready(function(){
  2. $("#addressForm").validate({
  3. debug: true,
  4. rules: {
  5. zip: {
  6. required: function(element){
  7. return $("#country").val() == "US";
  8. },
  9. rangelength: [5, 5]
  10. }
  11. }
  12. });
  13. $("#country").change(function(){
  14. $("#zipField").valid();
  15. })
  16. });