title: Java String - See if a string contains only numbers and not letters
body: <p>I have a string that I load throughout my application, and it changes from numbers to letters and such. I have a simple <code>if</code> statement to see if it contains letters or numbers but, something isn't quite working correctly. Here is a snippet.</p>
  
  <pre><code>String text = "abc"; 
  String number; 
  
  if (text.contains("[a-zA-Z]+") == false &amp;&amp; text.length() &gt; 2) {
      number = text; 
  }
  </code></pre>
  
  <p>Although the <code>text</code> variable does contain letters, the condition returns as <code>true</code>. The and <code>&amp;&amp;</code> should eval as both conditions having to be <code>true</code> in order to process the <code>number = text;</code> </p>
  
  <p>==============================</p>
  
  <p><strong><em>Solution:</em></strong> </p>
  
  <p>I was able to solve this by using this following code provided by a comment on this question. All other post are valid as well!</p>
  
  <p>What I used that worked came from the first comment. Although all the example codes provided seems to be valid as well!</p>
  
  <pre><code>String text = "abc"; 
  String number; 
  
  if (Pattern.matches("[a-zA-Z]+", text) == false &amp;&amp; text.length() &gt; 2) {
      number = text; 
  }
  </code></pre>