简体   繁体   English

为什么此RegEx与电话号码不匹配? 怎么修?

[英]Why doesn't this RegEx match the phone number? How to fix?

I have this phone number: +44 (0) 1234 123456 我有这个电话号码:+44(0)1234 123456

which the following regex is attempting to validate, but fails: 以下正则表达式试图验证的结果,但失败:

var regexPhone = new Regex(@"^(\\+)?([0-9\\s\\-])*$");

Can somebody tell me why it's failing? 有人可以告诉我为什么它失败了吗? Is it possible to change this so that it will validate the number above? 是否可以更改此设置,以便验证上面的数字?

Your regex does not allow any brackets. 您的正则表达式不允许使用方括号。

See if Jabos's answer to this question can help you along. 看看Jabos对这个问题的回答是否可以帮助您。

我建议您使用The Regulator调试您的正则表达式。

As Jens pointed out, your regex does not allow brackets. 正如Jens所指出的,您的正则表达式不允许使用方括号。

^(\+)((\([0-9\s\-]*\))|([0-9\s\-]))*$

This regex should work. 这个正则表达式应该起作用。 It allows some digits to be inside brackets also. 它也允许一些数字放在方括号内。

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

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