HTML
<asp:TextBox ID="txtmailingaddress1" runat="server" CssClass="textboxNormalLeftAligned inputField textarea200" TextMode="MultiLine" MaxLength="15" onkeyDown="checkTextAreaMaxLength2(this,event,'20');" />
From Last character will be deleted.
$('.textarea200').keyup(function () {
var limit = 200; // parseInt($(this).attr('maxlength'));
var text = $(this).val();
var chars = text.length;
if (chars > limit) {
var new_text = text.substr(0, limit);
$(this).val(new_text);
}
});
-----------------------------------------------------------------------------------------
Character will not deleted but you can input Enter between word.
$("textarea.textarea2002").keydown(function (event) {
var limit = 200;
var text = $(this).val();
var chars = text.length;
alert(chars);
if ((event.keyCode == null) || (event.keyCode == 0) || (event.keyCode == 8) || (event.keyCode == 9) || (event.keyCode == 13) || (event.keyCode == 27) || (event.keyCode == 33) || (event.keyCode == 34) || (event.keyCode == 35) || (event.keyCode == 36) || (event.keyCode == 37) || (event.keyCode == 38) || (event.keyCode == 39) || (event.keyCode == 40) || (event.keyCode == 46)) {} else {
if (chars <= limit) {} else {
event.preventDefault();
}
}
});
-----------------------------------------------------------------------------------------
You cant enter any value between string after 200 character length
function checkTextAreaMaxLength(textBox, e, mLen) {
var mLen = textBox["MaxLength"];
if (null == mLen)
mLen = length;
var maxLength = parseInt(mLen);
if (!checkSpecialKeys(e)) {
if (textBox.value.length > maxLength - 1) {
if (window.event) //IE
e.returnValue = false;
else //Firefox
e.preventDefault();
}
}
}
function checkSpecialKeys(e) {
if (e.keyCode != 8 && e.keyCode != 46 && e.keyCode != 37 && e.keyCode != 38 && e.keyCode != 39 && e.keyCode != 40) {
return false;
} else {
return true;
}
}
-----------------------------------------------------------------------------------------
Run in JsFiddle:
http://jsfiddle.net/skpaik/L9brP