我只希望信件被接受到vb.net上的文本框 [英] I only want letter to be accepted into the textbox on vb.net

查看:139
本文介绍了我只希望信件被接受到vb.net上的文本框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试这样做,所以文本框只接受字母,但验证不工作。
即使当我输入数字,它处理它,并显示谢谢你的详细信息的第一个lblError,其中它实际上应该是输入有效的名称。
是他们的验证测试类似于IsNumeric这种类型的问题?
plz help

Ive been trying to do this, so the textbox only accepts letters, but the validation does not work. Even when I enter numbers it processes it and shows the first lblError of "Thankyou for your details", where it should actually be "Enter A Valid Name ". is their are validation test similar to IsNumeric for this type of problem? plz help

    Dim MyName As String
    If txtMyName.Text Then
        MyName = txtMyName.Text
        lblError.Text = "Thankyou for your details"
    Else
        lblError.Text = "Enter A Valid Name "

    End If

End Sub

结束班

我需要简单的方法,没有什么与[a-zA-Z0-9]或RegEx模式,因为研究这些,我不能使用它们。

And I need simple methods, nothing with [a-zA-Z0-9], or RegEx patterns, as ive researched these and I cannot use them.

谢谢你

推荐答案

您可以检查文本字符串,即textbox1.text,以确保除了.Leave中的字母字符,事件。例如,当用户标签到下一个控件时,这将捕获错误。您可以使用正则表达式(本示例中为import System.Text.RegularExpressions)执行此操作,也可以手动检查文本。

You can check the text string, i.e., textbox1.text, to make sure it has nothing besides alphabet characters in the .Leave event. This will catch an error when the user tabs to the next control, for example. You can do this using a regular expression (import System.Text.RegularExpressions for this example), or you can check the text "manually."

Private Sub TextBox1_Leave(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox1.Leave
  If Not Regex.Match(TextBox1.Text, "^[a-z]*$", RegexOptions.IgnoreCase).Success Then
    MsgBox("Please enter alpha text only.")
    TextBox1.Focus()
  End If

End Sub

如果您希望在按下非Alpha键后立即停止用户,则可以使用TextChanged事件。离开事件。

If you want to stop the user as soon as a non-alpha key is pressed, you can use the TextChanged event instead of the .Leave event.

这篇关于我只希望信件被接受到vb.net上的文本框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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