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
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
{
int i=int.Parse("");
}
catch
{
//不是整数
}
^[0-9]*$或者:
try
{
long l=long.Parse(this.textBox1.Text);
}
catch
{
MessageBox.Show("您输入的不是整数!");
}
Regex r32 = new Regex(@"^[\d]+$");if (r32.IsMatch(str32))
{
//全部是数字
}
else
{
//包含有不是数字的字符
}