求一个文本框只能输入数字和字母(在15-20位之间)的正则验证表达式!!!

2025-06-26 06:07:14
推荐回答(1个)
回答1:

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