VB.Net 检查标点符号
VB.Net check punctuation
我有一个按键事件将输入限制为数字,如下所示:
Private Sub txtWeight_KeyPress(sender As Object, e As KeyPressEventArgs) Handles txtWeight.KeyPress
If Not Char.IsNumber(e.KeyChar) Then
e.Handled = True
End If
End Sub
但我也想增加输入句点的可能性,所以我尝试将代码更改为:
Private Sub txtWeight_KeyPress(sender As Object, e As KeyPressEventArgs) Handles txtWeight.KeyPress
If Not Char.IsNumber(e.KeyChar) AndAlso Not Char.IsPunctuation(e.KeyChar) Then
e.Handled = True
End If
End Sub
但是如您所知,该程序允许我输入每个标点符号,我想将其限制为仅“.”。我如何检查输入的标点符号?
e.Handled = e.KeyChar <> "."c AndAlso Not Char.IsNumber(e.KeyChar)
我有一个按键事件将输入限制为数字,如下所示:
Private Sub txtWeight_KeyPress(sender As Object, e As KeyPressEventArgs) Handles txtWeight.KeyPress
If Not Char.IsNumber(e.KeyChar) Then
e.Handled = True
End If
End Sub
但我也想增加输入句点的可能性,所以我尝试将代码更改为:
Private Sub txtWeight_KeyPress(sender As Object, e As KeyPressEventArgs) Handles txtWeight.KeyPress
If Not Char.IsNumber(e.KeyChar) AndAlso Not Char.IsPunctuation(e.KeyChar) Then
e.Handled = True
End If
End Sub
但是如您所知,该程序允许我输入每个标点符号,我想将其限制为仅“.”。我如何检查输入的标点符号?
e.Handled = e.KeyChar <> "."c AndAlso Not Char.IsNumber(e.KeyChar)