This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes submit blank fields Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "submit blank fields" Watch "submit blank fields" New topic
Author

submit blank fields

soumya kalla
Greenhorn

Joined: Jun 05, 2006
Posts: 12
In a login screen, when a user submits a blank page without entering a username and password, it should show an error message. What methods should I use to check that the fields are blank when submitted?

Soumya
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38107
    
  22
What sort of object are you using for your input? A JTextField? If you are checking the input with the getText() methods, you get a String. There are methods for checking the length of Strings, so you can send out an error message if the length comes to zero.

There are other possibilities.

CR
prasanna kanth
Greenhorn

Joined: May 14, 2006
Posts: 28
Hi soumya Kala,

If ur using with JTextfield, the below snippet will work fine,
first u get the value and trim it then find the length, if it equals to zero prompt the message to the user the field can't be balnk.

if u use only length, the user may give empty space so, use with trim


Hope! This snippet will help u
PrasannA
[ June 08, 2006: Message edited by: prasanna kanth ]
soumya kalla
Greenhorn

Joined: Jun 05, 2006
Posts: 12
Thankyou! I used the lengths and tried the application. It worked.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: submit blank fields
 
Similar Threads
Comparing values using JSTL
To clear the default values in the form
Read and Write doubts
Strust2 validation problem
Problem with Struts2 validation