title: Regular expression to check allowed characters not working in Java
body: <p>I have the following method to check allowed characters:</p>
  
  <pre><code>private boolean checkIfAllCharsAreValid(String test) {
      boolean valid = false;
      if (test.matches("^[a-zA-Z0-9,.;:-_'\\s]+$")) {
          valid = true;
      }
      return valid;
  }
  </code></pre>
  
  <p>but if test has the character <code>-</code> in it the match return false. Do i have to escape the <code>-</code>?</p>