简体   繁体   中英

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

I have this phone number: +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.

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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