欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

使用 ASCII 码限制输入内容

程序员文章站 2024-03-17 15:00:52
...

背景:

在学生信息管理系统中有的地方需要限制输入的内容。

措施:

限制输入的文本为大小写字母以及数字
Private Sub txtSID_KeyPress(KeyAscii As Integer)
    Select Case KeyAscii
        Case 8
        Case Asc("a") To Asc("z")
        Case Asc("0") To Asc("9")
        Case Asc("A") To Asc("Z")
        Case Else
        KeyAscii = 0
    End Select
End Sub

限制特殊的字符
Private Sub txtName_KeyPress(KeyAscii As Integer)
    If KeyAscii > 0 And Key < 8 Then KeyAscii = 0 
    If KeyAscii > 8 And Key < 65 Then KeyAscii = 0
    If KeyAscii > 90 And Key < 97 Then KeyAscii = 0
    If KeyAscii > 122 And Key < 127 Then KeyAscii = 0
    Select Case KeyAscii
    	Case 8
    End Select
End Sub
说实话,老是觉得这个博客有点水,毕竟是自己的能力不行,所以还请大佬们在评论区补充,我补充进正文区。(sharing is power)!

相关标签: ASCII