Private Sub Form_Load()
Text1.MaxLength = 10 '限制输入字符数
End Sub
Private Sub Text1_KeyPress(KeyAscii As Integer)
Select Case KeyAscii
Case 48 To 57 '只能输入数字
Case Else
KeyAscii = 0
End Select
End Sub
在响应事件时判断输入的字符是否符合要求,不符合则删除或返回0
Private Sub Form_Load()
Text1.Text = ""
Text1.MaxLength = 11
End Sub
Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii = 8 Or KeyAscii = 46 Then Exit Sub
If KeyAscii >= 48 And KeyAscii <= 57 Then Exit Sub
If KeyAscii >= 65 And KeyAscii <= 90 Then Exit Sub
If KeyAscii >= 97 And KeyAscii <= 122 Then Exit Sub
If KeyAscii = 13 Then SendKeys "{Tab}"
KeyAscii = 0
End Sub