jQuery in Action, 3rd edition
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
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "submit blank fields" Watch "submit blank fields" New topic

submit blank fields

soumya kalla

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?

Campbell Ritchie

Joined: Oct 13, 2005
Posts: 46375
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.

prasanna kanth

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
[ June 08, 2006: Message edited by: prasanna kanth ]
soumya kalla

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
It's not a secret anymore!