title: Check String with only Numbers in Java/Android
body: <p>I have string which has numbers and text. (Numbers have decimal values too.) I would like to check the strings contains <strong>only</strong> numbers with decimal values. </p>
  
  <p>Here is the string: </p>
  
  <pre><code>String testValue = "One Time Password(OTP) for Debit Card ending 1234 is 359573. Pls use this OTP at HDFC Bank ATM(Language selection screen) to create your ATM PIN before 27Jan15"
  </code></pre>
  
  <p>I am extracting the value to get only number in another piece of code. which I am storing in testValue. Sometime I get the full message like above and for which I am trying to find if the testValue has only numbers...So 
  I tried the following:</p>
  
  <pre><code>if (Pattern.matches("[a-zA-Z]+", testValue ) == false &amp;&amp; testValue.length() &gt; 2) 
  {
    Log.e("True","Only numbers);                  
  }
  </code></pre>
  
  <p>This is printing True.</p>
  
  <pre><code>if (testValue.contains("[0-9]+"))
  {
      Log.e("True","Only numbers);
  }
  </code></pre>
  
  <p>This is printing True too.</p>
  
  <pre><code>if (testValue.matches(".*\\d+.*")
  {
          Log.e("True","Only numbers);
      }
  </code></pre>
  
  <p>This is printing True too.</p>
  
  <p>All the above conditions are printing true I am not sure why as it contains numbers and alphabets?</p>
  
  <p>How do I get check if testValue has only numbers (decimals too)</p>
  
  <p>Thanks!</p>