我想用keyPress事件验证文本框。它应该允许字母表和"(“和")”我已经为字母表检查写了代码,但不知道如何检查"(“和")”。
Private Sub txtBankName_KeyPress(sender As Object, e As KeyPressEventArgs) Handles txtBankName.KeyPress
If Not (Asc(e.KeyChar) = 8) Then
If Not ((Asc(e.KeyChar) >= 97 And Asc(e.KeyChar) <= 122) Or (Asc(e.KeyChar) >= 65 And Asc(e.KeyChar) <= 90) Or Asc(e.KeyChar) = 32) Then
e.KeyChar = ChrW(0)
e.Handled = True
End If
End If
End Sub发布于 2017-02-03 05:31:33
这允许所有字母和"(“& ")”。请参考这两个问题:
How can I validate a string to only allow alphanumeric characters in it?
Only allow specific characters in textbox
Private Sub txtBankName_KeyPress(sender As Object, e As KeyPressEventArgs) Handles txtBankName.KeyPress
If System.Text.RegularExpressions.Regex.IsMatch(e.KeyChar.ToString(), "[^a-zA-Z0-9()\b]") Then
e.Handled = True
End If
End Subhttps://stackoverflow.com/questions/42017226
复制相似问题