title: Validating 7 digit phone number
body: <p>What I'm trying to accomplish is the following...
  Asks user for number and check to see if number provided by user input is a 7 digit integer.
  If it's a string, throw InputMismatchException and ask again for the number. Is there an easy way to accomplish this other than using regex and provided that the number is in the form 1234567? The other problem is if I input a value such as 12345678, it gets rounded due to int, so how do avoid this.</p>
  
  <pre><code>int number = 0;
  try {
      number = scan.nextInt();    // Phone Number is 7 digits long - excludes area code
  } catch(InputMismatchException e) {
      System.out.println("Invalid Input.");
      number = validateNumber(number, scan);
  } finally {
      scan.nextLine();    // consumes "\n" character in buffer
  }
  
  // Method checks to see if the phone number provided is 7 digits long
  // Precondition: the number provided is a positive integer
  // Postcondition: returns a 7 digit positive integer
  public static int validateNumber(int phoneNumber, Scanner scan) {
       int number = phoneNumber;
       // edited while((String.valueOf(number)).length() != 7) to account for only positive values
       // Continue to ask for 7 digit number until a positive 7 digit number is provided
       while(number &lt; 1000000 || number &gt; 9999999) {
          try {
              System.out.print("Number must be 7 digits long. Please provide the number again: ");
              number = scan.nextInt();    // reads next integer provided
          } catch(InputMismatchException e) { // outputs error message if value provided is not an integer
              System.out.println("Incorrect input type.");
          } finally {
              scan.nextLine();    // consumes "\n" character in buffer
          }
       }
       return number;
  }
  </code></pre>