[英]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)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.