字母&的文本框验证数字 [英] TextBox Validation for alphabets & numbers
本文介绍了字母&的文本框验证数字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好
我要求在文本框中仅输入字母和数字,不能输入任何特殊符号.我正在使用以下代码
Hi All
I have a requirement to input in a text box only alphabets and numbers no any special symbols. I m using below code
Private Sub txtLastName_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtLastName.TextChanged
If Not Regex.Match(txtLastName.Text, "^[a-z]*$", RegexOptions.IgnoreCase).Success Then
MessageBox.Show("Please enter alphabets only", "Add Contact", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1)
txtLastName.Focus()
End If
End Sub
但是它只允许使用字母,但是我也需要数字.我该怎么办?请帮助
but it allow only alphabets but I need numbers also.What should I do? Please help
推荐答案
",RegexOptions.IgnoreCase).成功" ," 添加联系人",MessageBoxButtons.OK,MessageBoxIcon.Information,MessageBoxDefaultButton.Button1) txtLastName.Focus() 结束 如果 结束 子
", RegexOptions.IgnoreCase).Success Then MessageBox.Show("Please enter alphabets only", "Add Contact", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1) txtLastName.Focus() End If End Sub
但是它只允许使用字母,但是我也需要数字.我该怎么办?请帮助
but it allow only alphabets but I need numbers also.What should I do? Please help
将此正则表达式用于字母数字.
Use this regular expression for alpha numeric.
^[a-zA-Z0-9]+
这篇关于字母&的文本框验证数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文