Amanjot Singh
Amanjot Singh

Reputation: 29

Avoid blank spaces in textbox

I want to prevent a user from entering blank spaces into a username textbox.I would be very grateful to the person,if anyone answered

Upvotes: 0

Views: 3623

Answers (4)

Maxim Gueivandov
Maxim Gueivandov

Reputation: 2385

You can also use FilteredTextBoxExtender control from AjaxControlToolkit. It will ease your application's maintenance if you need to change or add other forbidden characters some day.

See example here: FilteredTextBox Sample

Upvotes: 0

KBBWrite
KBBWrite

Reputation: 4419

    $('INPUT[type=text]').keypress(function(e) {

                   if (window.event) 
                       keycode = window.event.keyCode;
                   else if (e) 
                       keycode = e.which;
                   else return true;

                   if ((keycode == 32) ) //Space KeyCode
                   {
                       return false;
                   }
                   else {
                       return true;
                   }

               });

Upvotes: 1

Javed Akram
Javed Akram

Reputation: 15354

Use Javascript code as below:

<input type="text" name="myText" onKeypress="if (event.keyCode == 32) event.returnValue = false;"/>

tested in Internet Explorer

Upvotes: 2

Lucas S.
Lucas S.

Reputation: 547

you have to use something in javascript or jquery to avoid it. I suggest you a Jquery pluglin, my favorite one is that:

http://www.meiocodigo.com/projects/meiomask/

Upvotes: 1

Related Questions