Home > Code > Javascript > Restrict the characters in a textarea using javascript

Restrict the characters in a textarea using javascript

by Thamil   on Dec 12, 2010   Category: Javascript   |  Views: 1253    |  Points: 25   |  Gold 

The below sample JavaScript code will help you to restrict length of the textarea.

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="TestWeb.RestCharacters.WebForm1" %>

<!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 characters</title>
<script type="text/javascript">
function RestrictChar(txtField, limit)
if (txtField.value.length > limit)
txtField.value = txtField.value.substring(0, limit);
<form id="form1" runat="server">
<asp:TextBox ID="TextBox1" runat="server" Height="78px" onKeyDown="RestrictChar(this.form.TextBox1,10);" onKeyup="RestrictChar(this.form.TextBox1,10);"
TextMode="MultiLine" Width="350px"></asp:TextBox>



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