Skip to main content
April 25, 2006
Question

No Spaces in text form.

  • April 25, 2006
  • 4 replies
  • 905 views
Hi, I have a form and in the form I have a text box where the user can input his or her username. However, I dont want to allow them to be able to submit an username with spaces.
For example if the following were usernames:
GoodUsername - is what i want.
Bad User Name -what i dont want and want to prevent users from submitting these kinds of usernames.

please any kind of help will be appreciated. thanks.
This topic has been closed for replies.

4 replies

Known Participant
May 10, 2006
If you want to explore flash forms you can set up a mask to disallow spaces I believe.

Lots of opinions here, mine would be to not alter a user's submission on their behalf (for reasons asounds mentions and others). I prefer to use javascript, wddx, now ActionScript and Flash Remoting to verify what they've done before submission, and place as friendly of an error as possible on the screen before allowing submission. My preference is to have the user understand why they must submit something a particular way if it's important for the site. For a username for example, I don't think rm'ing spaces on their behalf is the best move. If I used a site and tried a username that didn't fit their format, I would personally want a 2nd chance at making a compliant one rather than the system making it compliant and dictating to me what it will be.
Inspiring
May 10, 2006
Since no one has answered the question. Can you supply more info?
Are you using an HTML or Flash form?
Do you want to do this in JavaScript before the form is entered?
Or after the form is submitted and handle on the server-side?

Also look into CFFORM and CFINPUT with field validation. Check the docs.
http://livedocs.macromedia.com/coldfusion/7/htmldocs/wwhelp/wwhimpl/js/html/wwhelp.htm?href=part_cfm.htm
May 10, 2006


<script>
str = str.replace(/^\s*|\s*$/g,"")
</script>

I think this will remove all the space from the string .

Inspiring
April 26, 2006
To elaborate on dempster's reply, it is a lot easier to program computers than it is to program people. The most user freindly option is to accept what they give you and get rid of the spaces yourself.
asounds
Inspiring
May 9, 2006
quote:

Originally posted by: Dan Bracuk
the most user freindly option is to accept what they give you and get rid of the spaces yourself.


I would have to disagree on this.

Give them an error message about not allowing spaces.

Otherwise, if you strip out the spaces, they will be calling and emailing you that they cannot log into your site. That is because you changed thier login. Our site use to be the same way. We stripped out the spaces. I finally had it changed. To many "stupid users". Even though we had in large bold red text that 'spaces were not allowed', users cannot read.
Participating Frequently
May 9, 2006
quote:

To many "stupid users"..... users cannot read.


Amen brother! The more that you do to idiot proof your site, the better that you will sleep at night. If you assume that "nobody would ever enter data like that" you will get eventually get burned. People will do some of the stupidest and oddball things, so you have to protect the application.

Press any key.....I can't find the "any" key!

Phil
Inspiring
April 26, 2006
When the form is submitted, you can check the string for spaces and display an error message if found. Or you can just remove all spaces in the string. The string functions Find and Replace would do this for you.