Extending verify.js for dropdowns and text fields

Hey all,

I’ve been really digging verify.js ([http://verifyjs.com][1]) and want to extend it for use in one of my forms. Having some trouble getting this to work. I’m more of a PHP guy and haven’t quite wrapped my brain around jQuery.

I have a dropdown in my form for cell phone carrier and another field for cell phone. The trick is, if they select a carrier and don’t enter a phone number, I need to prompt them to enter a phone number. If they enter a phone number and don’t select a carrier, I need to prompt them to select a carrier.

Would anyone be willing to provide some insight or at least point me in the right direction?

Thanks! :slight_smile:

You need to add a custom group rule.

If you take a look at the docs:

then you can start from here (untested!):

$.verify.addGroupRules({

    phone: function(r) {
      var carrier = r.field("carrier"),
          number = r.field("number");

      if(carrier.length === 0 && number.length !== 0) {
        r.warn("Missing carrier information...");
        return true;
      }

      if(carrier.length !== 0 && number.length === 0) {
        r.warn("Missing cell number information...");
        return true;
      }

    }
});

and the HTML for the fields

<form>
  <input value="" data-validate="phone#carrier">
  <input value="" data-validate="phone#number">
  <input type="submit" class="submit">
</form>