9 Replies Latest reply on May 10, 2006 2:17 PM by furious70

    No Spaces in text form.

    WOLFcfm Level 1
      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.
        • 1. Re: No Spaces in text form.
          dempster Level 1
          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.
          • 2. Re: No Spaces in text form.
            Dan Bracuk Level 5
            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.
            • 3. Re: No Spaces in text form.
              asounds
              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.
              • 4. Re: No Spaces in text form.
                paross1 Level 2
                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
                • 5. Re: No Spaces in text form.
                  Dan Bracuk Level 5
                  quote:

                  Originally posted by: asounds
                  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.


                  Why didn't you strip out the spaces on their subsequent login attempts?
                  • 6. Re: No Spaces in text form.
                    dempster Level 1
                    Why don't we all embrace the sterotype of arrogant tech guys who have to put up with stupid users?

                    The fact is, on web pages people skim and read quickly and we often need to adjust our approach to conform to user behavior. Yes, it's frustrating when people don't read instructions. But it's frustrating for users when web forms scold them, force them to enter data in strange formats, require fields that have nothing to do with the transaction, etc. etc.

                    In this case, if there is a legitimate reason for excluding spaces from a username, you can explain that on the form. And when someone puts a space in anyway, why not just correct and notify them that it was corrected? Does it enhance the user experience to flash a big "ERROR! STUPID USER!" message at them?

                    It's like requiring users to enter a field in uppercase. If the user doesn't type the field in uppercase, do we yell at them? Or just convert it to uppercase?
                    • 7. No Spaces in text form.
                      drforbin1970 Level 1
                      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?hre f=part_cfm.htm
                      • 8. Re: No Spaces in text form.
                        flooker


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

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

                        • 9. Re: No Spaces in text form.
                          furious70
                          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.