View Single Post
 
I've returned with more Java help
Reply
Posted 2010-04-24, 11:59 AM
I'm validating a first name entered into a the java.swing GUI textbox. It must start with Uppercase, follow Lowercase, and no numbers. For some reason one if statement is being ignored for displaying the error messagebox.

Code:
jtext1.addActionListener (
		             new ActionListener() {
		                public void actionPerformed(ActionEvent e) {
		 				   string1=jtext1.getText();
		 				   if(!string1.substring(0,1).matches("[A-Z]")){
		 				        errorReport+=errorUpper;
		 				        errorDetect=true;
		       				}
		       				if(!string1.substring(1,string1.length()).matches("[a-z]*")){
		 						errorReport+=errorLower;
		 						errorDetect=true;
		 					}
		 					for (i=0; i<string1.length(); i++){
		 						if (Character.isDigit(string1.charAt(i))) {
		 							errorReport+=errorAlpha;
		 							errorDetect=true;
		 							break;
		 						}
		 					}
		 					if (errorDetect=true){
		 						JOptionPane.showMessageDialog(null, errorReport);
							}
							errorDetect=false;
							errorReport="Error: ";
		                   jtext2.requestFocus();
		                }
		             }
		          );
Thank you for wasting your time to help me
"Ban shampoo, demand real poo"
Old
Profile PM WWW Search
Slyvr enjoys the static noises of ten television sets simultaneously tuned to 412.84 MHzSlyvr enjoys the static noises of ten television sets simultaneously tuned to 412.84 MHz
 
 
Slyvr