文本框验证接受数字,+, - 和空格 [英] Textbox validation to accept numbers,+,- and empty space
本文介绍了文本框验证接受数字,+, - 和空格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
我想对文本框进行验证,这是一个接受数字的电话号码,符号如+, - ,空的空间
例如+49 561 56789-0
Hi All,
I want to do a validation to a text box which is a phone number which accepts numbers,symbols like "+","-",empty space
e.g +49 561 56789-0
Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
If Asc(e.KeyChar) < 48) _
Or Asc(e.KeyChar) > 57) Then
e.Handled = True
End If
If (Microsoft.VisualBasic.Asc(e.KeyChar) = 8) Then
e.Handled = False
End If
end sub
我知道这只会检查数字,但我需要包含两个符号+, - ......不知道我该怎么做。
请帮忙。谢谢。
I know this would check only numbers but i need to include two symbols "+","-"...Not sure how do i do this.
Please help. Thanks.
推荐答案
你听说过 RegEx [ ^ ]?
所有你需要做的就是使用 IsMatch [
您可以在这里找到的示例模式:
http://regexlib.com/DisplayPatterns.aspx?categoryId=7&AspxAutoDetectCookieSupport=1 [ ^ ]
http://www.regular-expressions.info/examples.html [ ^ ]
Have you ever heard about RegEx[^]?
All you need to do is to use IsMatch[^] method with pattern to telephone number.
Example patterns you'll find here:
http://regexlib.com/DisplayPatterns.aspx?categoryId=7&AspxAutoDetectCookieSupport=1[^]
http://www.regular-expressions.info/examples.html[^]
这篇关于文本框验证接受数字,+, - 和空格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文