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
  • 39,517
  • 70
  • 210
  • 376

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
  • 24,655
  • 6
  • 74
  • 116
0

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

Stefan Dragnev
  • 13,273
  • 6
  • 46
  • 50
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,449
  • 8
  • 62
  • 86