求一个文本框只能输入数字和字母(在15-20位之间)的正则验证表达式!!!
2个回答
展开全部
Private Sub Text1_KeyPress(KeyAscii As Integer)
Select Case KeyAscii
Case 97 To 122, 65 To 90, 48 To 57 'a-z 'A-Z '0-9
If Len(Text1.Text) > 19 Then KeyAscii = 0
Case 8, 9, 13 '退格键,TAB,ENTER
Case Else
KeyAscii = 0
End Select
End Sub
Private Sub Text1_LostFocus()
If Len(Text1.Text) < 15 Then MsgBox "不小于15位": Text1.SetFocus
End Sub
Select Case KeyAscii
Case 97 To 122, 65 To 90, 48 To 57 'a-z 'A-Z '0-9
If Len(Text1.Text) > 19 Then KeyAscii = 0
Case 8, 9, 13 '退格键,TAB,ENTER
Case Else
KeyAscii = 0
End Select
End Sub
Private Sub Text1_LostFocus()
If Len(Text1.Text) < 15 Then MsgBox "不小于15位": Text1.SetFocus
End Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询