使用If Staments仅接受文本框中的字母数字数据 [英] Using If Staments for accepting Alphanumeric data in Textboxes only

查看:156
本文介绍了使用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


这篇关于使用If Staments仅接受文本框中的字母数字数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆