white space question

Discussion in 'ASP .Net Web Controls' started by Rob Eventine, Feb 9, 2008.

  1. Rob Eventine

    Rob Eventine Guest

    hi all,
    is there a way to eliminate a 'space character' (the space bar being
    pressed) from the beginning of a line?

    eg:
    hello
    as opposed to
    hello

    thanks in advance
    Rob Eventine, Feb 9, 2008
    #1
    1. Advertising

  2. The solution would obviously involve using either JavaScript or a Validator,
    which I am assuming you already knew. If you want to use JavaScript, here
    are the best solution I could come up with:

    Use the onchange JavaScript event handler to call a function that removes
    any spaces from the beginning of the line. This will remove any spaces from
    the beginning when the user leaves the TextBox, therefore preventing them
    from submitting a string that starts with a space.

    However, my recommendation would be to use the RegularExpressionValidator.

    There are obviously other JavaScript algorithms and other Validators that
    would work as well, but these would be my top choices for each one.
    --
    Nathan Sokalski

    http://www.nathansokalski.com/

    "Rob Eventine" <> wrote in message
    news:Dnlrj.7668$...
    > hi all,
    > is there a way to eliminate a 'space character' (the space bar being
    > pressed) from the beginning of a line?
    >
    > eg:
    > hello
    > as opposed to
    > hello
    >
    > thanks in advance
    >
    >
    >
    >
    Nathan Sokalski, Feb 9, 2008
    #2
    1. Advertising

  3. Rob Eventine

    Scott M. Guest

    You could do it with a client-side JavaScript and regular expressions (i.e.
    a RegularExpression Validator control). Or, depending on your needs, you
    could just allow it and then use the .Trim() method of the sting object to
    remove any leading or trailing spaces from the input on the server-side.

    Scott


    "Rob Eventine" <> wrote in message
    news:Dnlrj.7668$...
    > hi all,
    > is there a way to eliminate a 'space character' (the space bar being
    > pressed) from the beginning of a line?
    >
    > eg:
    > hello
    > as opposed to
    > hello
    >
    > thanks in advance
    >
    >
    >
    Scott M., Feb 11, 2008
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Shuo Xiang

    Stack space, global space, heap space

    Shuo Xiang, Jul 9, 2003, in forum: C Programming
    Replies:
    10
    Views:
    2,863
    Bryan Bullard
    Jul 11, 2003
  2. Christian Seberino
    Replies:
    21
    Views:
    1,621
    Stephen Horne
    Oct 27, 2003
  3. Ian Bicking
    Replies:
    2
    Views:
    978
    Steve Lamb
    Oct 23, 2003
  4. Ian Bicking
    Replies:
    2
    Views:
    706
    Michael Hudson
    Oct 24, 2003
  5. Ben C
    Replies:
    6
    Views:
    2,131
    Leif K-Brooks
    Jan 28, 2007
Loading...

Share This Page