How do i allow the format
xxx-xxx-xxxx?
import java.util.regex.Pattern;
import javax.swing.JOptionPane;
public class Test{
public static void main(String args[]) {
while(true){
String phoneNumber = JOptionPane.showInputDialog("What is your phone number ?");
if((Pattern.matches("[0-9]{3}-[0-9]{3}-[0-9]{4}", phoneNumber)))
break;
else
JOptionPane.showMessageDialog(null, phoneNumber + " is invalid," + " please enter a valid 10 digit number");
}
}
}
Here i used regex to allow the format xxx-xxx-xxxx. Please check the bold statement in the code.
Let me know if you have any queries or clarifications.... :)
How do i allow the format xxx-xxx-xxxx? String phoneNumber = JOptionPane . showinputDialog ( "What is...
Write a program in Python to solve the following task: In this project, you will build a phone number from digits entered by your user. Your program will loop until 10 valid digits have been entered. It will then use those digits to display the phone number entered using the format: XXXXXXXXXX (or (XXX) XXX – XXXX for extra credit). The program will ask for a digit, it will check to see if the digit is actually between 0 and...
build a phone number from digits entered by your user. Your program will loop until 10 valid digits have been entered. It will then use those digits to display the phone number entered using the format: XXXXXXXXXX (or (XXX) XXX – XXXX for extra credit). The program will ask for a digit, it will check to see if the digit is actually between 0 and 9 inclusively. If so, the digit will be stored as the next number in the...
In this programming assignment we will review string and character manipulations. You will be developing a Java program that will prompt users for person’s last name, year of birth, and employee number in a predefined specific format. You will then parse the input string and print it in separate lines along with validations. The input format will be of the form :,< employee number > You will need to separate three segments in order to print it as: Last name...
Java Help Please: I'm doing something wrong with my while loop. I want my code to check the phone number that is input to make sure it matches. If it doesn't I want it to print out Error! and I want my While loop to ask the user to try again by inputting another phone number. When the user puts in a phone number that matches I want the program to continue to output my tokens. When I run this...
i nedd to know how to fix it
import javax.swing.JOptionPane: public class Conv void length (double d) JOptionPane.showMessageDialog(null, "the equvialent cm 13 "+(double) /100) double length() double d-Double. parseDouble (JOptionPane. ShowMessageDialog(null,"enter the meter value return d*100.0: void distance (double d) JOptionPane. showMessageDialog(null,"the equvialent meter is : "+(double) /1000); double distance() double d-Double. parseDouble (JoptionPane. showMessageDialog(null, enter the kilometna return a 1000; SLOVO publie main(String args) Conv c-new Conv(): boolean b=true; while(b) { int a Integer.parseInt(JOption Pane.showMessageDialog(null, "Enterin l.to convert to...
Hello I need help with this. I am trying to use JOptionpane to ask 5 questions. However I cannot get the program to do anything after an initial selection is made. Here is the assignment. Write an application that creates a quiz, which contains at least five questions about a hobby, popular music, astronomy, or any other personal interest. Each question should be a multiple choice question with at least three options. When a user answers a question correctly, display...
This is the source code: Please incorporate the Exception
Handling
import javax.swing.JOptionPane;
import java.awt.*;
public class GuessingGame {
public static void main(String[] args) {
int computerNumber = (int) (Math.random() * 10 + 1);
System.out.println("The correct guess would be " +
computerNumber);
int userAnswer = 0;
int count = 0;
while (computerNumber != userAnswer) {
count++;
String response = JOptionPane.showInputDialog(null,
"Enter a guess between 1 and 10");
userAnswer = Integer.parseInt(response);
String result = null;
if (userAnswer == computerNumber) {
result =...
This is Python
The program should accept input from the user as either 7-digit
phone number or 10-digit. If the user enters 7 characters, the
program should automatically add "512" to the beginning of the
phone number as the default area code. Dash (hyphen) characters do
not count in input character count, but must not be random. If the
user enters dashes the total character count must not exceed
12.
The program should not crash if the user enters invalid...
I need the following written in Java please, thank you
'
We want you to implement a java class that will show details on users and throw exceptions where needed. The following requirements specify what fields you are expected to implement in your User class: - A private String firstName that specifies the first name of the user - A private String lastName that specifies the last name of the user - A private int age that specifies user's age...
Please help, Array does not print properly. I need to print out the 8 class numbers entered by the user ! Java only using J option pane, you cannot use ulti or anything else only J option pane Program compiles but does not print the array correctly! import javax.swing.JOptionPane; public class programtrial { public static void main(String[] args) { int newclass = 0; int countclass = 0; final int class_Max = 8; int[] classarray =...