white space question

R

Rob Eventine

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
 
N

Nathan Sokalski

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.
 
S

Scott M.

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,046
Latest member
Gavizuho

Latest Threads

Top