title: Java String validation via blacklist
body: <p>I want to write a simple validator to throw an exception if a String contains "illegal characters", specifically:</p>
  
  <blockquote>
    <p>~, @, +, % and |</p>
  </blockquote>
  
  <p>I'm searching for the cleanest way of doing this, and was hoping that there was a way to define a "blacklist" regex that might look something like:</p>
  
  <pre><code>String blacklist = "~@+%|";
  String toValidate = getInputFromUser();
  
  if(toValidate.matches(blacklist))
      throw new RuntimeException("Illegal characters found!");
  </code></pre>
  
  <p>However I know that the regex is incorrect. Am I heading in the right direction or am I way off base (i.e. is there a much simpler solution)? Thanks in advance!</p>