Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
JavaScript: Limit the number of characters in a textarea
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
<!-- Code source: THANKS -->
<html xmlns="">
<title>Limit Number of Characters in a TextArea</title>
<script type='text/javascript'
<script type='text/javascript'>
$(document).ready(function() {
$('#ta').keyup(function() {
var len = this.value.length;
if (len >= 150) {
this.value = this.value.substring(0, 150);
$('#charLeft').text(150 - len);
<textarea id="ta" cols="20" rows="8"></textarea><br/>
(Maximum characters: 150)<br/>
<span id="charLeft"> </span> Characters left
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.