In this assignment, you will prompt the user to input their username, their user password and their telephone number (no hyphens, periods, spaces, or any other special characters). You will use regex to validate the user’s password and telephone number. You will also format the user’s telephone number with parentheses around the area code and a hyphen between the 3rd and 4thdigit of the remaining numbers.
Write methods to:
• Use regex to validate that the user entered their first name and last name
• Use regular expressions to make sure the password meets the requirements of 10 characters consisting of a combination of letters, digits, and the underscore. The password must start with a letter. If it doesn’t, prompt the user to enter another password.
• Use regex to make sure the user enters a 10 digit telephone number. If it doesn’t fit the criteria, the user must reenter the number. Using both the String and StringBuilder classes, add parentheses and a hyphen (ex: the telephone number should be represented as (555) 555-5555). This means you will do it both ways, once using a String and the other using aStringBuilder. You should initially set them using the user input, then add the parentheses and hyphen using the methods learned in this chapter. Print out the user’s name and formatted telephone numbers from the String class and from the StringBuilder class with descriptive text.

Solution PreviewSolution Preview

These solutions may offer step-by-step problem-solving explanations or good writing examples that include modern styles of formatting and construction of bibliographies out of text citations and references. Students may use these solutions for personal skill-building and practice. Unethical use is strictly forbidden.

package regex;
import java.util.regex.*;

* @author USER
public class RegEx {

    * @param args the command line arguments
    public static void main(String[] args) throws IOException
       BufferedReader br = new BufferedReader(new InputStreamReader(;
       String UserName;
       String FirstName;
       String LastName;
       String Psw;      
       String telephoneNoByString;
       String telephoneNoByStringBuilder;
       String telephoneStr;
//       System.out.println("Please enter user name");
//       UserName = br.readLine();
       System.out.println("Please enter First Name");
       FirstName = br.readLine();
            System.out.println("Please enter correct First Name");
            FirstName = br.readLine();

By purchasing this solution you'll be able to access the following files:

for this solution

or FREE if you
register a new account!

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Find A Tutor

View available Java Programming Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Upload a file
Continue without uploading

We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats