-2
[DataType(DataType.PhoneNumber)]
[RegularExpression("^([0-9 .()-+)$", ErrorMessage = CommonConstants.PhoneError)]

public string PhoneNumber { get; set; }

I have a PhoneNumber field. With this field I want to give a permission for user, just type number or +,-,),(. How can I have a RegularExpression ?

Tieson T.
  • 20,657
  • 5
  • 74
  • 89
  • Possible duplicate of [A comprehensive regex for phone number validation](http://stackoverflow.com/questions/123559/a-comprehensive-regex-for-phone-number-validation) – Mick Oct 30 '15 at 04:07

1 Answers1

1

Your current regex has an unterminated character group ([ with no ]). You want something like this:

^([\d() +-]+)$

Note the order of + and - - - is a range indicator, so it needs to be first, last, or escaped (as in \-).

Here's a demo.

elixenide
  • 43,445
  • 14
  • 72
  • 97