我讲一下我以前的做法不知对你可有帮助,自己写一个函数,当键盘事件触发时,判断输入的字符是数字带是字符可以通过ASCII码来判断,可以自行过滤掉数字或字符,由你自己决定.

解决方案 »

  1.   

    看看http://expert.csdn.net/Expert/topic/2222/2222583.xml?temp=.4305994
      

  2.   

    在对用户控件进行输入验证时一般使用正则表达式,例:
    1.定义一个文本框
    <td>
        <ASP:TextBox id=TextBox1 runat=server />
    </td>
    2.加入正则表达式验证(假设你要求输入的是全数字)
    <td>
     <asp:RegularExpressionValidator id="RegularExpressionValidator1" runat="server"
                ControlToValidate="TextBox1"
                ValidationExpression="^[0-9]*$"
                Display="Static"
                Font-Name="verdana" Font-Size="10pt">
                    只能输入数字
     </asp:RegularExpressionValidator>
    </td>
      

  3.   

    在Win Form 下也可以使用Validator
      

  4.   

    使用脚本:
    定义一个文本框:<ASP:TextBox id=TextBox1 runat=server />
    只能输入数字的脚本如下:
    <script language="vbscript">
    Sub TextBox1_onBlur
        IF len(Form1.TextBox1.value)=0 then
    alert ("请输入数值!")
    exit sub
        end if

        IF IsNumeric(Form1.TextBox1.value)=false then
    alert ("必须为数值!")
    Form1.TextBox1.focus ()
    exit sub
    end if
              End Sub
    </script>