Results 1 to 5 of 5
Thread: Java Codeing Help
- 11-18-2011, 09:11 AM #1
Member
- Join Date
- Nov 2011
- Posts
- 10
- Rep Power
- 0
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
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 knowJava 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;
Thank YouLast edited by JosAH; 11-18-2011 at 09:57 AM. Reason: added [code] ... [/code] tags.
- 11-18-2011, 10:01 AM #2
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,408
- Blog Entries
- 7
- Rep Power
- 17
Re: Java Codeing Help
Shouldn't you check TxtEmail.getText().contains("@") instead? (the same appplies for the ".")
kind regards,
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
- 11-18-2011, 10:17 AM #3
Member
- Join Date
- Nov 2011
- Posts
- 10
- Rep Power
- 0
Re: Java Codeing Help
Thanks for thank Jos
- 11-18-2011, 10:20 AM #4
Member
- Join Date
- Nov 2011
- Posts
- 10
- Rep Power
- 0
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 03:59 PM. Reason: code tags added
-
Re: Java Codeing Help
Let's format your code better. Please see my comments in your code:
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).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;
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.


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks