Win a copy of Svelte and Sapper in Action this week in the JavaScript forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

check for a space with the form bean validate method

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
does anybody have any idea??
PLEASE HELP!!!
 
jakes vandenberg
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • 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
  • 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.
 
See ya later boys, I think I'm in love. Oh wait, she's just a tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic