谢谢!

解决方案 »

  1.   

    Function isInteger(ByVal para)
            On Error Resume Next
            Dim str
            Dim l, i
            If para Then
                isInteger = False
                Exit Function
            End If
            str = CStr(para)
            If Trim(str) = "" Then
                isInteger = False
                Exit Function
            End If
            l = Len(str)
            For i = 1 To l
                If Mid(str, i, 1) > "9" Or Mid(str, i, 1) < "0" Then
                    isInteger = False
                    Exit Function
                End If
            Next
            isInteger = True
            If Err.Number <> 0 Then Err.Clear()
        End Function
      

  2.   

    try
    {
    int i=int.Parse("");
    }
    catch
    {
    //不是整数
    }
      

  3.   

    正则表达式:
    ^[0-9]*$或者:
    try
    {
    long l=long.Parse(this.textBox1.Text);
    }
    catch
    {
    MessageBox.Show("您输入的不是整数!");
    }
      

  4.   

    可以用TestBox的Keydown事件控制不让键入除数字键外的其他字符
      

  5.   

    using System.Text.RegularExpressions;string str32 = "12345";
    Regex r32 = new Regex(@"^[\d]+$");if (r32.IsMatch(str32))
    {
        //全部是数字
    }
    else
    {
        //包含有不是数字的字符
    }
      

  6.   

    楼上的正解,千万不要用try {} catch{}来做判断.
      

  7.   

    Int32.TryParse("123", out n);
      

  8.   

    try catch对性能影响比较大,建议使用客户端脚本用正则表达式来判断