用正则表达式验证就可以了。
‘下面是输入后按按钮,如果输入成功显“OK”
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If Regex.IsMatch(TextBox1.Text, "^[a-zA-Z\d\+\-\?\\\\.\*\|\(\)\{\}\^\&\$\n\r\t\v\f\]*$") Then
MsgBox("OK!!")
Else
TextBox3.Text = ""
End If
End Sub
If Not (IsNumeric(e.KeyChar) Or e.KeyChar = Microsoft.VisualBasic.ChrW(8) Or & _ e.KeyChar = Microsoft.VisualBasic.ChrW(46)) Then
e.Handled = True
End If
Private Sub TxtTest_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles TxtTest.TextChanged
Dim strText As String = TxtTest.Text.Trim
Dim strLast As String
If strText = "" Then Exit Sub
strLast = strText.Substring(Len(strText) - 1)
If strLast <> Encoding.ASCII.GetString(Encoding.ASCII.GetBytes(strLast)) Then
TxtTest.Text = strText.Replace(strLast, "")
TxtTest.SelectionStart = Len(TxtTest.Text)
End If
End Sub