Zelaron Gaming Forum

Zelaron Gaming Forum (http://zelaron.com/forum/index.php)
-   Tech Help (http://zelaron.com/forum/forumdisplay.php?f=329)
-   -   I've returned with more Java help (http://zelaron.com/forum/showthread.php?t=50144)

Slyvr 2010-04-24 11:59 AM

I've returned with more Java help
 
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 ^_^

Lenny 2010-04-24 12:24 PM

If(errorDetect==true){

That'll probably sort it.

Slyvr 2010-04-25 05:43 PM

Yeah, I'm retarded. I just realized that a few minutes after posting this haha


All times are GMT -6. The time now is 01:54 PM.

Powered by vBulletin® Version 3.8.2
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
This site is best seen with your eyes open.