Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

submit blank fields

 
soumya kalla
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 48917
58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thankyou! I used the lengths and tried the application. It worked.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic