Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Entering in a strictly 10 digit phone number.

843789Oct 11 2009 — edited Oct 11 2009
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");
	}
	
	
	
	
	
	
	
	
   }			
}

}
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Nov 8 2009
Added on Oct 11 2009
19 comments
3,515 views