Javascript validation on multiline texbox for character count-2
<script type="text/javascript">
function checkTextAreaMaxLength(textBox, e, length) {
var mLen = textBox["MaxLength"];
if (null == mLen)
mLen = length;
var maxLength = parseInt(mLen);
if (!checkSpecialKeys(e)) {
if (textBox.value.length > maxLength - 1) {
textBox.value = textBox.value.substring(0, maxLength);
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;
}
</script>
<asp:TextBox Rows="5" Columns="20" Width="180px" ID="txtDescription" MaxLength="150"
onkeyDown="checkTextAreaMaxLength(this,event,'150');"
TextMode="multiLine" runat="server"> </asp:TextBox>
---------------------
0 comments:
Post a Comment