I am doing a customer information scanner project for school, currently I am working on the phone number portion. I need to have the customer enter their phone number and I need to detect as many errors as possible.
This includes: make sure it’s all digits, make sure its ten digits, then to divide into – <3 digit String for Area Code> <3 digit String for Central Office > <4 digit String for Station Code> and finally add dashes between the area code, central office, and station code. Are there any easy ways to do this, here is my current code. Thanks in advance
enter code here//===================================================================================================================================
System.out.println(DATA_DIV);
System.out.println("nCustomer Phone Number Information");
System.out.println("-----------------------------------n");
System.out.println("Enter the Phone Number:");
phoneNumber = uIn.next();
if (phoneNumber.matches("\d+")) {
} else {
Garbage = uIn.next();
System.out.println("ntError Data Type: you entered ( " + Garbage + " ) for Phone Number");
System.out.println("Phone Number must be made up of numbers only");
System.out.println();
System.out.println("Re-Enter the Phone Number :");
phoneNumber = uIn.next();
}