现在的位置: 首页 > 综合 > 正文

char limit validation in multiline asp.net textbox

2013年10月12日 ⁄ 综合 ⁄ 共 1452字 ⁄ 字号 评论关闭

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <style type="text/css">
        .alertmessage
        {
            color:#FF0000;
        }
    </style>
    <script type="text/javascript" src="../js/jquery-1.4.2.min.js"></script>
    <script type="text/javascript">
        $(document).ready(function () {
            var minCount = 5;
            var maxCount = 200;
            var inputBox = $('#<%=txtInput.ClientID %>');
            inputBox.bind("cut copy paste", function (e) {
                e.preventDefault();
            });
            inputBox.keypress(function () {
                var strCount = inputBox.val().length;
                $('#<%=txtCount.ClientID %>').val(strCount);
                if (strCount < minCount || strCount > maxCount) {
                    $('#message').text("Please key in characters in the range 5 -200");
                }
                else {
                    $('#message').text("");
                }
            })
        });
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <table>
            <tr>
                <td>
                    <asp:TextBox ID="txtInput" runat="server" TextMode="MultiLine" Rows="7" Width="300px"></asp:TextBox>
                </td>
            </tr>
            <tr>
                <td>
                    number of char<asp:TextBox ID="txtCount" runat="server" ReadOnly="true"></asp:TextBox>
                </td>
            </tr>
        </table>
    </div>
    <div id="message" class="alertmessage">
    </div>
    </form>
</body>
</html>

抱歉!评论已关闭.