如何验证电话号码和 - [英] How to Validation phone number and -
本文介绍了如何验证电话号码和 - 的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
对于电话号码的验证并包含 -
For the validation for the phone number and included -
@^ \ +(?:[0-9]?){6,14} [ 0-9] $
@"^\+(?:[0-9] ?){6,14}[0-9]$"
我必须验证电话号码 -
I have to validate phone number with -
示例333-333-3333 (哪个是有效号码)。
example 333-333-3333 (Which is valid number).
如何自定义有效的正则表达式 - 电话号码
how to customize the valid Regex with - into phone number
推荐答案
这取决于你想要的严格程度,看起来这个正则表达式并不是特别严格。
这个正则表达式说:
well it depends on how strict you want to be it doesn't seem like this regex is especially strict. this regex says:
- 从行首开始
- 匹配一个
+
(或者可能是1或0)似乎
不明确(但可能不依赖于实现),因为
捕获括号:()
分解\ +
和的关系?
- 可能放错地方
:
- 匹配任何数字
0-9
1或0次6-14次 - 然后一位
0-9
- 然后结束。
- start at beginning of line
- match one
+
(or maybe 1 or 0) which seems ambiguous (but may not be depending on implementation) because the capture parentheses:()
breaks up the relationship of the\+
and the?
- possibly misplaced
:
- match any digit
0-9
1 or 0 times 6-14 times - then one digit
0-9
- then end of line.
你还注意到任何反斜杠都必须加倍...... @\\b
用于单词边界。
您可能想尝试类似......
also you note that any backslash will have to be doubled... @"\\b"
for a word boundary.
you may want to try something like...
@"\\b[\\d]{3}\\-[\\d]{3}\\-[\\d]{4}\\b"
would I think match your example, but it wouldn't match
(555) 555 - 5555 or
555.555.5555 or
+44 1865 55555
这篇关于如何验证电话号码和 - 的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文