如何不接受TextBox中的数字?

时间:2015-06-30 00:04:08

标签: vb.net

我知道怎么做以上相反的事情。它只接受数字,但它接受0123456789以外的所有内容怎么样?

代码我仅用于数字。

If Asc(e.KeyChar) <> 8 Then

            If Asc(e.KeyChar) < 48 Or Asc(e.KeyChar) > 57 Then
                My.Computer.Audio.PlaySystemSound(System.Media.SystemSounds.Asterisk)
                e.Handled = True

            End If

        End If
    End If

3 个答案:

答案 0 :(得分:2)

尝试这个。

If Not Char.IsLetter(e.KeyChar) And Not e.KeyChar = Chr(Keys.Delete) And Not e.KeyChar = Chr(Keys.Back) Then    
    e.Handled = True
End If

答案 1 :(得分:2)

您可以使用Char.IsDigit判断字符是否为十进制数字。

If Char.IsDigit(e.KeyChar) Then
    My.Computer.Audio.PlaySystemSound(System.Media.SystemSounds.Asterisk)
    e.Handled = True
End If

答案 2 :(得分:1)

只是颠倒了条件?

QLocale::setDefault(QLocale::c());