• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

check for a space with the form bean validate method

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here is my scenario:
I have an input box on my form. If I highlight text and press space to clear it, the form still contains a space, but no text.
In my form bean I have a validate method and was wondering how I can check for this space.
I tried the following without success:

if (Code2 == "") {

if (Code2 == "\u0020") {

if (Code2 == " ") {

Thanks
 
jakes vandenberg
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
does anybody have any idea??
PLEASE HELP!!!
 
jakes vandenberg
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
peeps,
Nevermind, I figured it out. I just had to think about it a little bit and go back to "RTFM"!!

Since it is a String, use String.equals(" ").
 
pie sneak
Posts: 4727
Mac VI Editor Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It might be more efficient to trim it and compare it to empty string so that you can handle a string with multiple spaces.

Code2.trim().equals("");

OR you could set up a filter to automatically trim all incoming request parameters. That would make such validation unnecessary.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic