使用If Staments仅接受文本框中的字母数字数据
问题描述:
先生和女士下午好
您能帮我在Visual Basic 2015 Express中找到仅接受文本框中字母数字数据的If语句命令吗?谢谢.
Can You help me find an If statement command that only accepts Alphanumeric data in textboxes In Visual Basic 2015 Express? Thank You.
此致,
小詹姆斯·德伦·霍兰德
James Delorn Howland Jr.
答
您能帮我在Visual Basic 2015 Express中找到仅接受文本框中字母数字数据的If语句命令吗?
Can You help me find an If statement command that only accepts Alphanumeric data in textboxes In Visual Basic 2015 Express?
通常的过程是遍历字符串中的字符并测试ASCII值的数字范围.对于某些编码,可能会失败.
The usual procedure would be to iterate over the characters in the string and test for a numeric range of ASCII values. That may fail for certain encodings.
For Each c As Char In TextBox1.Text
If AscW(c) < 48 OrElse (AscW(c) > 57 AndAlso AscW(c) < 65) OrElse (AscW(c) > 90 AndAlso AscW(c) < 97) OrElse AscW(c) > 122 Then
MsgBox("Invalid")
Exit For
End If
Next