Blog

Restrict Space and Special Character using Javascript

Posted by Vaibhav Kale Blogs | JavaScript, CSS 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();" />

post comment
     
COMMENT USING
PREMIUM SPONSORS
DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and add new content to existing PDF documents from within your applications.
SPONSORED BY
  • PDF reports have never been easier to create. With our included WYSIWYG Designer, you can layout your reports, set up your data source and let DynamicPDF ReportWriter do the rest.
Get Career Advice from Experts