Q:

Validating 7 digit phone number

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.
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 < 1000000 || number > 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;
}

A:

A valid telephone number is not necessarily an integer (Containing a + sign for country codes for example). So use a String instead. 
Simple example with basic regex (7 digits, not validating country codes etc.):
public class Test {
    public static void main(String[] args) {
        Scanner stdin = new Scanner(System.in);

        String telephoneNumber = stdin.nextLine();

        System.out.println(Pattern.matches("[0-9]{7}", telephoneNumber));

    }
}

