0

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?

DaveDev
  • 41,155
  • 72
  • 223
  • 385

3 Answers3

1

Your regex does not allow any brackets.

See if Jabos's answer to this question can help you along.

Community
  • 1
  • 1
Jens
  • 25,229
  • 9
  • 75
  • 117
0

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

Stefan Dragnev
  • 14,143
  • 6
  • 48
  • 52
0

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.

Draco Ater
  • 20,820
  • 8
  • 62
  • 86