VB2005中,如何限制文本框只输入数字或汉字或其他?

2025-03-18 20:17:32
推荐回答(2个)
回答1:

Private Sub Text1_KeyPress(KeyAscii As Integer) Dim tMsg As String Select Case KeyAscii Case Asc(0) To Asc(9) tMsg = "输入的是数字" Case Is < 0 tMsg = "输入的是汉字或双字节字符" Case Asc("@"), Asc("$") tMsg = "输入的是“@”符号或“$”符号" Case Else tMsg = "输入的是其它" End Select MsgBox tMsg End Sub Private Sub Text1_KeyPress(KeyAscii As Integer) '如果限制输入数字可使用下面的例程 Select Case KeyAscii Case Asc(0) To Asc(9) Case Else KeyAscii = 0 End Select End Sub

回答2:

使用正则表达进行控制!!!