• 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
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

Stop Users from entering blanks in text form fiels

 
Ranch Hand
Posts: 449
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How can we stop users from entering blanks in text form fiels. I could not find trim feature in the javascript.
 
Ranch Hand
Posts: 214
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Vijay,
If by "blanks", you mean that the user has declined to enter anything in the fields, something like this should work:


Hope that helps!
g.
 
Ranch Hand
Posts: 4716
9
Scala Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
since he mentioned trim() function, i think by blanks he means spaces. i believe you will have to parse the string looking for the space character which is, i believe, #160(or nbsp in IE but not netscape4.7). then you will have to remove them somehow. even if there is a trim() function it will only remove leading and trailing spaces. im pretty sure this has been done before. you can probly find a ready made script somewhere.
 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have one javascript function which parses the string passed to it and if there are any spaces in it, the function returns true.
Here is the code :
function areSpacesPresent(sStringToCheck)
{
var bAreSpacesPresent = false;
for(var iCounter=0 ; iCounter<sStringToCheck.length ; iCounter=iCounter+1)
{
if (sStringToCheck.charAt(iCounter) == " ")
{
bAreSpacesPresent = true;
}
}
return bAreSpacesPresent;
}
 
Sheriff
Posts: 67756
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Or, you could extend the String class itself with a trim method:

and then use it in your validation function.
hth,
bear
[ August 08, 2002: Message edited by: Bear Bibeault ]
 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I use reguar expresssions for stuff like that...
Using that with String.prototype would be the best, but how is browser support for editing the prototype? I've only used it fo IE...
[ August 08, 2002: Message edited by: Matt Howard ]
reply
    Bookmark Topic Watch Topic
  • New Topic