如何在vb.net中通过数字,字母和特殊字符限制文本框 [英] How to restrict textbox whether by numbers, letter and special characters in vb.net
问题描述
Hello Guys,
我正在寻找可能有关如何通过字母,数字或特殊字符来限制文本框的人。
我有一些用来限制文本框的鳕鱼:
Hello Guys,
I m'looking for someone who may help concerning how to restrict textbox whether by letters, numbers or specials characters.
I got some cods that used to restrict Text box bellow:
Private Sub TextBox1_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
If Not Char.IsLetterOrDigit(e.KeyChar) Then
e.Handled = True
End If
End Sub
他们正在使用keyPress但不使用文本更改,所以我需要使用文本更改,可以在输入错误时提供消息进入。我继续做我的研究,我达到了以下代码,但我不知道如何更改它们以便它们可以为数字工作以及它们如何使用特殊字符,请帮助我。代码如下:
they are working with keyPress but not working with text-change, so I need that work with text change that can provide a message when wrong input is entered. I continued doing my research I reached to the following code, but I did not know how I can change them so that they can work for numbers and also how they can work with special character, please help me out. the codes were these bellow
Public Class MainForm
Dim charactersDisallowed As String = "1234567890"
Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
Dim theText As String = TextBox1.Text
Dim Letter As String
For x As Integer = 0 To TextBox1.Text.Length - 1
Letter = TextBox1.Text.Substring(x, 1)
If charactersDisallowed.Contains(Letter) Then
theText = theText.Replace(Letter, String.Empty)
End If
Next
TextBox1.Text = theText
TextBox1.Select(TextBox1.Text.Length, 0)
End Sub
End Class
我想知道如何将它们用于数字津贴和特殊字符津贴。
I want to know how I can apply them for numbers allowance and special characters allowance.
推荐答案
访问这里......
http://www.vbforums.com/showthread.php ?570438-Restrict-TextBox-to-only-certain-characters-numeric-or-symbolic [ ^ ]
Visit Here...
http://www.vbforums.com/showthread.php?570438-Restrict-TextBox-to-only-certain-characters-numeric-or-symbolic[^]
这篇关于如何在vb.net中通过数字,字母和特殊字符限制文本框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!