Restrict Space and Special Character using Javascript

By Vaibhav Kale Blogs | JavaScript Feb 04, 2013
This blog shows how to restrict users from entering space and special character in textbox using Javascript.

function RestrictSpaceSpecial(e) {
    var k;
    document.all ? k = e.keyCode : k = e.which;
    
return
 ((k > 64 && k < 91) || (k > 96 && k < 123) || k == 8 || k == 32 || (k >= 48 && k <= 57));
}

Now access the JavaScript function on keypress event of textbox as shown below:

<asp:TextBox ID="TextBox2" runat="server" onkeypress="RestrictSpaceSpecial();" />

COMMENT USING

PREMIUM SPONSORS

Hire Mobile & Web Developer on demand. 100% satisfaction. Try for 1 week or Money Back. Local and remote developers available all over USA.

Latest Blogs