title: Check if string taken with Scanner.next() contains number
body: <p>I wanted to take a String using Scanner.next() and see if it contains a number or not. I used regex to check if a string contains anything but a number. The regex works correctly if the string is hard coded, but not when taken from keyboard. I expected input of 5 to be detected as a number, but it is not. Please tell me why. My code:</p>
  
  <pre><code>import java.util.Scanner;
  
  public class Error {
  
      public static void main(String[] args) {
  
          Scanner inp = new Scanner(System.in);
          int num = 0;
          String input = "";
          boolean isStringNumber = true;
  
          System.out.println("\nPlease enter a number only...");
          input = inp.nextLine();
  
          isStringNumber = input.contains("[^0-9]+");
  
          if (isStringNumber == false) {
              System.out.println("\nYou entered a non number " + input);
          }
  
      }
  
  }
  </code></pre>