vb如何判断文本框输入的字符为小写字母和数字

2025-04-09 03:07:36
推荐回答(3个)
回答1:

可以当数据完全输入完毕,在按钮单击事件里,执行处理程序前,加以判断:
dim i as integer
for i=1 to len(text1.text)
if (mid(text1.text,i,1)>="0" and mid(text1.text,i,1)<="9") Or _
(mid(text1.text,i,1)>="a" and mid(text1.text,i,1)<="z") Then
msgbox "输入的数据只包含数字和小写字母"
else
msgbox "输入的数据包含 [数字和小写字母] 之外的字符!"
end if
next i

回答2:

根据输入字符的ASCII值判断。

Private Sub Text1_KeyPress(KeyAscii As Integer)
    If KeyAscii >= 48 And KeyAscii <= 57 Or KeyAscii >= 97 And KeyAscii <= 122 Then
        Text1 = Text1
    Else
        KeyAscii = 0
    End If
End Sub

回答3:

楼上的不想要,那你想要什么