Hey guys,
I am doing the validation for a phone number, I did the validation for a zip code and it was exactly the same so I don't see why I keep getting the JOptionPane popup ive created for phone number validation when I enter in 10 zeroes or any other numbers.
Here is the code:
import javax.swing.JOptionPane;
public class Validator {
public static void main(String[] args){
Customer aCust = new Customer();
aCust.address = JOptionPane.showInputDialog("Please enter an address:");
aCust.firstName = JOptionPane.showInputDialog("Please enter your first name:");
aCust.lastName = JOptionPane.showInputDialog("Please enter your last name:");
aCust.state = JOptionPane.showInputDialog("Please enter the two character abbreviation for your state:");
try{
aCust.zip = Integer.parseInt(JOptionPane.showInputDialog("Please enter a five digit zip code:"));
aCust.phone = Integer.parseInt(JOptionPane.showInputDialog("Please enter a ten digit phone number:"));
}
catch(NumberFormatException ex){
}
if (aCust.address.equalsIgnoreCase("") || aCust.firstName.equalsIgnoreCase("") || aCust.lastName.equalsIgnoreCase("")){
JOptionPane.showMessageDialog(null, "Please make sure all fields are filled in.");
}
if (aCust.state.equalsIgnoreCase("") || aCust.state.length() != 2){
JOptionPane.showMessageDialog(null, "Make sure the state field is not blank and that it is two characters long");
}
if (String.valueOf(aCust.zip).equalsIgnoreCase("") || String.valueOf(aCust.zip).length() != 5){
JOptionPane.showMessageDialog(null, "Please check to make sure the zip code is five DIGITS long and is not blank");
}
if (String.valueOf(aCust.phone).equalsIgnoreCase("") || String.valueOf(aCust.phone).length() != 10){
JOptionPane.showMessageDialog(null, "Please make sure the phone number is not blank and consists only of 10 DIGITS without other characters");
}
}
}
}