Results 1 to 5 of 5
  1. #1
    Richard5324 is offline Member
    Join Date
    Nov 2011
    Posts
    10
    Rep Power
    0

    Default Java Codeing Help

    i am writing a code for a buttion when click to check a text field for Email sines Such as @ and . and also that it has to be 10 or more char i got these code so far dose anyone no were i am going wrong it dosent seen to work

    Java Code:
    if (TxtEmail.getText().trim().length() < 10) {
                JOptionPane.showMessageDialog(rootPane, "Invalid Email");
               }
                if (TxtEmail.toString().contains("@")){
                      return;}
                else{JOptionPane.showMessageDialog(rootPane, "Invalid Email Need @");}
    
                      if (TxtEmail.toString().contains(".")){
                      }else{ JOptionPane.showMessageDialog(rootPane, "Invalid Email Need .");}
                      return;
    i got the 10 char to work but i cant seem to get the @ and the . to work also working on net beans if u needed to know
    Thank You
    Last edited by JosAH; 11-18-2011 at 10:57 AM. Reason: added [code] ... [/code] tags.

  2. #2
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,785
    Blog Entries
    7
    Rep Power
    21

    Default Re: Java Codeing Help

    Shouldn't you check TxtEmail.getText().contains("@") instead? (the same appplies for the ".")

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  3. #3
    Richard5324 is offline Member
    Join Date
    Nov 2011
    Posts
    10
    Rep Power
    0

    Default Re: Java Codeing Help

    Thanks for thank Jos

  4. #4
    Richard5324 is offline Member
    Join Date
    Nov 2011
    Posts
    10
    Rep Power
    0

    Default Re: Java Codeing Help

    i cant seem to get the 2nd one to work keep giving me a error (UNREACHERBAL TEXT)

    Java Code:
                if (TxtEmail.getText().contains("@")){}
                else{JOptionPane.showMessageDialog(rootPane, "Invalid Email Need @");}
                    return;
                if (TxtEmail.getText().contains(".")){}
                else{JOptionPane.showMessageDialog(rootPane, "Invalid Email Need @");}
                    return;
    Last edited by Fubarable; 11-18-2011 at 04:59 PM. Reason: code tags added

  5. #5
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default Re: Java Codeing Help

    Let's format your code better. Please see my comments in your code:

    Java Code:
    if (TxtEmail.getText().contains("@")){}
    else {
       JOptionPane.showMessageDialog(rootPane, "Invalid Email Need @");
    }
    
    return; // this will *** always *** be called 
    
    // when will this line ever be reached?
    if (TxtEmail.getText().contains(".")){}
    else { 
       JOptionPane.showMessageDialog(rootPane, "Invalid Email Need @"); 
    }
    
    return;
    Here's where your improper code formatting has hindered your ability to see what your code is actually doing, and shows the importance of use of proper code formatting. So the lesson is to be more careful with your formatting, to not be afraid to use whitespace to make your code more readable (but not too much whitespace).

    Also, I've added code tags to your post same as Jos to help make your code readable in this forum. please use them yourself when posting code in this forum. To do this, place the tag [code] above your code block, and [/code] below your block.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •