如何确定文本框是否仅包含数字字符 [英] How do I determine if a textbox contain numeric characters only
问题描述
大家好。
我正在尝试确定TextBox是否只包含数字字符。
我该怎么做?
我尝试过的事情:
这是我用过的代码,但它似乎不起作用。
Private Sub TextBox1_KeyPress(发件人为对象,
$ b $为KeyPressEventArgs)处理TextBox1.KeyPress
'检查是否用户仅在TextBox中输入数字。
如果Asc(e.KeyChar)<> 13并且也不是IsNumeric(e.KeyChar)<> 8然后
MessageBox.Show(请仅输入数字)
e.Handled = True
结束如果
End Sub
Hi all.
I'm trying to determine if a TextBox contain numeric characters only.
How do I do that?
What I have tried:
Here's the code that I've used, but it doesn't seem to work.
Private Sub TextBox1_KeyPress(sender As Object,
e As KeyPressEventArgs) Handles TextBox1.KeyPress
'Check if the user enter numbers only in the TextBox.
If Asc(e.KeyChar) <> 13 AndAlso Not IsNumeric(e.KeyChar) <> 8 Then
MessageBox.Show("Please enter numbers only")
e.Handled = True
End If
End Sub
推荐答案
'似乎无法正常工作' - 对于那些看不到你的屏幕的人来说真的没什么用处 - 提示:你需要更好地描述该程序的功能是你不想要的,反之亦然 - 并不是你想要它...
看看这个如何:创建一个数字文本框 [ ^ ]
'doesnt seem to work' - not really helpful for someone out here who cant see your screen - hint : you need to get better at describing what the program does that you dont want it to to or vice versa - doesnt do that you do want it to ...
have a look at this How to: Create a Numeric Text Box[^]
这篇关于如何确定文本框是否仅包含数字字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!