title: Regex validation - show offending character(s). javax.validation
body: <p>There's regex validation in JSR-303 (javax.validation). For example:</p>
  
  <pre><code>@Pattern(regexp="[\w_\\.]+")
  private String username;
  </code></pre>
  
  <p>The default message shown when the value is not valid (does not match the regex) is something like "Must match {regex}". But users don't understand regex, so it is irrelevant to show it to them. An option is to just show "The username contains illegal characters", and it will probably be fine in most cases. But it will be good to show which character is wrong.</p>
  
  <p>This cannot be directly achieved with regex - it either matches or not. You have to either define other patterns that miss some of the components, or try dropping characters from the string until it matches, and then show these characters to the user.</p>
  
  <p>That was in general. Another question is how to achieve this with javax.validation. </p>
  
  <p>So, to summarize the question:</p>
  
  <p>How to display the offending characters with javax.validation, so that the message looks like "The characters ?, * and $ are illegal"</p>