如何限制文本框只能输入汉字或数字、字母

作者在 2008-05-21 19:36:44 发布以下内容

'只能输入字母

Private Sub txtWord_KeyPress(KeyAscii As Integer)
If KeyAscii < 65 Or KeyAscii > 122 Then
    KeyAscii = 0
End If
End Sub

'只能输入汉字

Private Sub txt汉字_KeyPress(KeyAscii As Integer)
If Chr(KeyAscii) Like "[!一-龥]" Then
If KeyAscii <> 8 And KeyAscii <> 9 And KeyAscii <> 13 Then
KeyAscii = 0
End If
End If
End Sub

'只能输入数字

Private Sub txtNumber_KeyPress(KeyAscii As Integer)
If KeyAscii < 48 Or KeyAscii > 57 Then
    KeyAscii = 0
End If

End Sub

 

基本控件 | 阅读 3857 次
文章评论,共0条
游客请输入验证码
文章归档
最新评论