博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

验证TextBox只输入数字

Posted on 2008-09-03 10:38  hyd309  阅读(674)  评论(3编辑  收藏  举报

<asp:textbox class="Text"
        onkeypress="if (event.keyCode < 48 || event.keyCode >57) event.returnValue = false;"
 id="txtY_Revenue" style="TEXT-ALIGN: right" runat="server" Width="90%" MaxLength="12">
    </asp:textbox>

 

或者:

 if (Tbx_Edition.Text != "")
        {
            bool a1=true;
            foreach(char c in Tbx_Edition.Text)
            {
                if(char.IsNumber(c))
                {
                    continue;
                }
                else if(c=='.')
                {
                    continue;
                }
                else
                {
                    a1 = false;
                    break;
                }
            }

}