Home > Code > Javascript > Restrict space in textbox using JavaScript

Restrict space in textbox using JavaScript

by Thamil   on Feb 18, 2013   Category: Javascript   |  Views: 5520    |  Points: 25   |  Gold 

Below JavaScript code used to restrict the space in the textbox
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm23.aspx.cs" Inherits="WebApplication1.WebForm23" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Restrict the space in textbox using Javascript</title>
<script type="text/javascript">
function DisableSpace() {
if (event.keyCode == 32) {
event.returnValue = false;
return false;
<form id="form1" runat="server">
<asp:Label ID="Label1" runat="server" Text="Name"></asp:Label>
<asp:TextBox ID="txtLoginID" onkeypress="return DisableSpace()" runat="server"></asp:TextBox>
<br />
<asp:Label ID="Label2" runat="server" Text="Password"></asp:Label>
<asp:TextBox ID="txtPassword" TextMode="Password" runat="server"></asp:TextBox>
<br />
<br />
<asp:Button ID="btnLogin" runat="server" Text="Login" />

Post Code  |  Code Snippet Home

User Responses

No response found, be the first to review this code snippet.

Submit feedback about this code snippet

Please sign in to post feedback

Latest Posts