VB 如何验证提交的字符是否为:0,1,2,3,A,B,C

来源:百度知道 编辑:UC知道 时间:2024/06/14 05:40:00
如题!
如:TEXT1在的字符我只限制他只能是:0,1,2,3,A,B,C中的字符
如何进行验证?

'判断是否符合要求
Private Sub Command1_Click()
For i = 1 To Len(Text1.Text)
Select Case Mid(Text1.Text, i, 1)
Case "0", "1", "2", "3", "A", "B", "C"
Case Else
MsgBox "第" & i & "位不符合要求", vbOKOnly, "提示"
End Select
Next
End Sub

'让Text1只能输入某些字符
Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii >= Asc("0") And KeyAscii <= Asc("3") Or KeyAscii = 8 Or KeyAscii >= Asc("A") And KeyAscii <= Asc("C") Then
Else
KeyAscii = 0
End If
End Sub