title: Jquery unobtrusive custom error messages
body: <p>I created a custom jquery validation rule which checks for hex color:</p>
  
  <pre><code>$.validator.addMethod("hexcolor", function (value, element) {
      return this.optional(element) || /^(#){1}([a-fA-F0-9]){6}$/.test(value);
  }, "Please insert a valid hex color (#______)");
  
  $.validator.unobtrusive.adapters.add("hexcolor", function (options) {
      options.rules['hexcolor'] = options.params;
      options.messages['hexcolor'] = options.message;
  });
  </code></pre>
  
  <p>When i create my textbox, i have something like this</p>
  
  <pre><code>@Html.TextBoxFor(p =&gt; p.Color, new { data_val = "true", data_val_hexcolor = "Error message" })
  </code></pre>
  
  <p>I have two problems/questions:</p>
  
  <ol>
  <li><p>When the value is invalid, the error message is "Error message" instead of "Please insert a valid hex color (#_ _ _ _ _ _)"</p></li>
  <li><p>I've seen in some other examples error messages created like this.</p>
  
  <p>jQuery.validator.addMethod("maxWords", function (value, element, params) {
      return this.optional(element) || stripHtml(value).match(/\b\w+\b/g).length &lt; params;
  }, jQuery.validator.format("Please enter {0} words or less."));</p></li>
  </ol>
  
  <p>String placeholder "{0} {1}" etc are replaced with the values of the parameters?</p>