开发者

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

I have this phone number: +4开发者_开发百科4 (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.


I'd recommend you use The Regulator to debug your regex.


As Jens pointed out, your regex does not allow brackets.

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

This regex should work. It allows some digits to be inside brackets also.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜