title: Java regex require at least one letter and one digit. Also allow only selected special characters
body: <p>I tried researching for this, got it to partially work but when include the special characters, it won't work. On the special characters - it is NOT required but if a special character is used, it must only be the allowed special character (<code>@</code> and <code>-</code>(dash)).</p>
  
  <p>Tried this but it wont work. Anyone can help? by the way it should be at least 8 characters long</p>
  
  <pre><code>^(?=.*?[a-zA-Z])(?=.*?[0-9@-]).{8,}$
  </code></pre>
  
  <p>Some examples:</p>
  
  <pre><code>"JohnDoe" should be invalid
  "JohnDoe2" should be valid 
  "22222222" should be invalid 
  "22222222a" should be valid
  "JohnDoe2@" should be valid
  "JohnDoe2#" should be invalid
  "johndoe2" should be valid
  </code></pre>