title: How to only accept a String with certain characters in Java
body: <pre><code>for (int i = 0; i &lt; d.getFornavn().length(); i++) {
      char c = d.getFornavn().charAt(i);  
      if ((c &gt; 'a' &amp;&amp; c &lt; 'z') || (c &gt; 'A' &amp;&amp; c &lt; 'Z') || ( c == ' ' || c == '-')) {
          flag = true;
      }
  }
  </code></pre>
  
  <p>Hi! I'm trying to make a function that checks a string if it only has certain characters (only a-z, A-Z, the norwegian letters å,æ,ø,Å,Æ,Ø, whitespace and hyphen, but I'm having some trouble with that. I tried doing what you see here, but it's not working how I hoped it would (I didn't implement the norwegian letters yet, because I'm clueless on how to do that). </p>
  
  <p>I'm starting to think there must be a simpler way to check for this, but I haven't heard about anything.</p>
  
  <p>Any thoughts? </p>