Introduction:
here I will explain how to use jQuery to limit number of characters in textarea(textbox) even copy and paste text or jQuery restrict textbox(textarea) length even copy and paste text in textbox with example.
here I will explain how to use jQuery to limit number of characters in textarea(textbox) even copy and paste text or jQuery restrict textbox(textarea) length even copy and paste text in textbox with example.
Description:
In previous post I explained jQuery Tag cloud example in asp.net, jQuery show datatable on aspx page in asp.net, send html page as mail body in asp.net, how to send mail with attachment in asp.net and many more articles related to jQuery,asp.net, c# and vb.net. Now I will explain how to how to restrict textbox(textarea) length even copy and paste text in textbox with example in jQuery
In previous post I explained jQuery Tag cloud example in asp.net, jQuery show datatable on aspx page in asp.net, send html page as mail body in asp.net, how to send mail with attachment in asp.net and many more articles related to jQuery,asp.net, c# and vb.net. Now I will explain how to how to restrict textbox(textarea) length even copy and paste text in textbox with example in jQuery
To implement this we need
to write the code lilke as shown below
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>jQuery Limit Number of Characters in a TextArea</title>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.8.2.js"></script>
<script type='text/javascript'>
$(function()
{
$('#textarea1').keyup(function() {
var desc = $('#textarea1').val();
var len = desc.length;
if (desc.length >= 150) {
this.value = this.value.substring(0,
150);
}
$('#spntxt').text(150
- len + ' Characters Left');
});
});
</script>
</head>
<body>
<textarea id="textarea1"
cols="20"
rows="8"></textarea><br/>
<span id="spntxt">
150 Characters left</span>
</body>
</html>
|
Live
Demo
To check live demo try to copy and paste text in
textarea it will restrict to 150 characters
Enter Text:
150 Characters left |
If you enjoyed this post, please support the blog below. It's FREE! Get the latest Asp.net, C#.net, VB.NET, jQuery, Plugins & Code Snippets for FREE by subscribing to our Facebook, Twitter, RSS feed, or by email. |
|||
|
|||
1 comments :
If I Enter the character in text area wide out of range 150, It allows the character. but only shows the message for (0 Characters Left )
Note: Only a member of this blog may post a comment.