简体   繁体   English

C#中带有特殊字符的手机号码正则表达式

[英]Regex for mobile number with special characters in c#

I'm trying to build a regular expression to validate mobile numbers that accepts () , - and + . 我正在尝试构建一个正则表达式来验证接受()-+的移动电话号码。 I am totally new to this and this is what I could build 我对此完全陌生,这就是我可以建立的

\+?\(?([0-9])\)?[- ]?\(?([0-9])\)?

But I know this wrong since it is accepting data such as 123456- which is not right. 但是我知道这是错误的,因为它正在接受123456-这样的数据,这是不对的。 Can somebody please help me build a regex so that itdoes not accept inputs like 有人可以帮我建立一个正则表达式,以便它不接受诸如

123)3575
12349-
-2345678

There is no limit to the number of digits entered. 输入的位数没有限制。 I'm expecting it to accept inputs of type 我期望它接受类型的输入

(123)4567-67898
+234567890
1234-4567-67

Please help.. 请帮忙..

Something like 就像是

/^(\+|\(\d+\))?\d+(-\d+)*$/

Regex Demo 正则表达式演示

Test 测试

Regex.IsMatch("(123)4567-67898", @"^(\+|\(\d+\))?\d+(-\d+)*$");
=> True

Regex.IsMatch("-2345678", @"^(\+|\(\d+\))?\d+(-\d+)*$");
=> False

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM