Restrict user from entering unlimited characters in a multiline textbox
First of all add following code inside <head> tag ::
<script type="text/javascript" src="//code.jquery.com/jquery-1.10.2.js"></script>
<script type="text/javascript">
$(function () {
$('#txtdesc').keypress(function (e) {
var txt = $(this).val();
if (txt.length > 90) {
e.preventDefault();
}
});
});
</script>
Now add code in <body> tag ::
<div>
Enter Address(Should be Less than 90 Chars) <asp:TextBox ID="txtdesc" runat="server" TextMode="MultiLine"></asp:TextBox>
</div>
<script type="text/javascript" src="//code.jquery.com/jquery-1.10.2.js"></script>
<script type="text/javascript">
$(function () {
$('#txtdesc').keypress(function (e) {
var txt = $(this).val();
if (txt.length > 90) {
e.preventDefault();
}
});
});
</script>
Now add code in <body> tag ::
<div>
Enter Address(Should be Less than 90 Chars) <asp:TextBox ID="txtdesc" runat="server" TextMode="MultiLine"></asp:TextBox>
</div>
Great Work Aayush.. Really helpful !
ReplyDelete