title: jQuery validate custom rule in data attributes
body: <p>I have an input text which already has some validate rules</p>
  
  <pre><code>&lt;input type="text" value="" placeholder="Write the code here" 
         name="myCode" id="myCode" data-rule-required="true" 
         data-msg-required="Required field" class="form-control" 
         aria-required="true"&gt;
  </code></pre>
  
  <p>and have created a custom rule to validate the syntax of the code</p>
  
  <pre><code>$("#myCode").rules("add", { checkCode: 
      function () { 
          return $('input[name=codeText]').val(); 
      } 
  });
  </code></pre>
  
  <p>With this method I am defining that <code>myCode</code> should be validated by using also <code>checkCode</code> method which in turns receive in input the value of <code>codeText</code>.</p>
  
  <p>This works really very well. However to maintain clean the code I would like to move the rule definition inside a <code>data-*</code> attribute but I can't understand how to write the code to dynamically pass the equivalent of return <code>$('input[name=codeText]').val()</code>. Please have a look at the question marks below.</p>
  
  <pre><code>&lt;input type="text" value="" placeholder="Write the code here" 
         name="myCode" id="myCode" 
         data-rule-required="true" data-msg-required="Required field" 
         data-rule-checkCode="????" data-msg-checkCode="Invalid code" 
         class="form-control" aria-required="true"&gt;
  </code></pre>
  
  <p>What I have to put in the attribute value???</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>As per <a href="https://stackoverflow.com/a/33057995/431537">Sparky answer</a> I've ended up on putting all the selector on the attribute. Like this:</p>
  
  <pre><code>&lt;input type="text" value="" placeholder="Write the code here" 
     [...]
     data-rule-checkCode="input[name=codeText]" 
     [...]&gt;
  </code></pre>
  
  <p>and using it like this in my method</p>
  
  <pre><code>$.validator.addMethod("checkCode", function(value, element, param) {
      return $(param).val();
  }, '...');
  </code></pre>