vb登陆密码只能是字母和数字

来源:百度知道 编辑:UC知道 时间:2024/06/09 05:48:41
现在我想要用vb设置一个登陆窗体,要求是在登陆窗体中,密码输入要进行检测,只能输入字母(含大小写)和数字,且最多10位。急!!谢谢!!
我要的是具体的代码,谢谢

Private Sub Text1_KeyPress(KeyAscii As Integer)
If (KeyAscii >= 48 And KeyAscii <= 57) Or (KeyAscii >= 65 And KeyAscii <= 90) Or (KeyAscii >= 97 And KeyAscii <= 122) and (len(text1)<=10 )Then
Else
KeyAscii = 0
End If
End Sub

限制输入字母和数字,可以按下面的方法,长度为10,只要设置MaxLength属性为10就可以了
Private Sub Text1_KeyPress(KeyAscii As Integer)
Select Case KeyAscii
Case 48 To 57, 65 To 90, 97 To 122
Case Else
KeyAscii = 0
End Select
End Sub

来个正则表达式的,哈,不用设置MaxLength属性
Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii <> 8 Then
Dim re
Set re = CreateObject("VBScript.RegExp")
re.IgnoreCase = True
re.Global = True
re.Pattern = "^[A-Za-z0-9]{1,10}?$"
If Not re.test(Text1.Text & Chr(KeyAscii)) Then
KeyAscii = 0
End If
End