1. 该判断事件是TextBox的keypress 事件中进行判断的

2. 判断key(e.KeyChar)是不是数字、小数点、或者负号

3. 判断是否多次输入负号或者小数点

代码如下:

If IsNumeric(e.KeyChar) OrElse e.KeyChar = "." OrElse e.KeyChar = "-" Then

Dim strCash As String =TextBox1.Text

If strCash.Contains(".") Then

If strCash.Split(".").Length > 2 Then

e.Handled = True

End If

End If

If strCash.Contains("-") Then

If strCash.Split("-").Length > 2 Then

e.Handled = True

End If

If strCash.Substring(0, 1) <> "-" Then

e.Handled = True

End If

If strCash.Length > 1 Then

If strCash.Substring(1, 1) = "." Then

e.Handled = True

End If

End If

End If

ElseIf Not Asc(e.KeyChar) = Keys.Back Then

e.Handled = True

End If

代码如上,如果有问题,欢迎修改指正