textbox 只能输入数字 不为空

<asp:TextBox ID="txtPageNum" runat="server" CssClass="txtInput2 small2" AutoPostBack="True"

                OnTextChanged="txtPageNum_TextChanged" onkeypress="return (/[\d]/.test(String.fromCharCode(event.keyCode)));" >10</asp:TextBox>

            <asp:RegularExpressionValidator ID="revEnterNum" runat="server" ControlToValidate="txtPageNum"

                Display="Dynamic" ErrorMessage="请输入数字!" ValidationExpression="^([1-9][0-9]*)$"></asp:RegularExpressionValidator>

            <asp:RequiredFieldValidator ID="rfvNotEmpty" runat="server" ControlToValidate="txtPageNum"

                Display="Dynamic" ErrorMessage="不能为空,请输入数字!"></asp:RequiredFieldValidator>
 ////设置分页数量

    protected void txtPageNum_TextChanged(object sender, EventArgs e)

    {

        Page.Validate();

        if (Page.IsValid)

        {

          AspNetPager1.CurrentPageIndex = 1;

          AspNetPager1.PageSize = Convert.ToInt32(txtPageNum.Text.Trim());

          RptBind();

        }

    }

你可能感兴趣的:(只能输入数字)