Reputation: 1220
I am trying to write a regular expression that matches theese cases.
Phone number can be: 8 digits 0-9 OR 12 digits 0-9 OR 12 digits 0-9 and a + sign So: 12345678, 0012345678, +0012345678 are valid options
[RegularExpression("^[0-9]{8})|[0-9]+{12}|[0-9]{11}$", ErrorMessage = "Invalid phone")]
Would also be nice that on the + validation case, the plus sign have to be in the beginning (following 10 digits) and on the 12 digits validation there have to be 00 first (then following 10 digits)
Upvotes: 0
Views: 9279
Reputation: 174706
You could try the below regex,
@"^(?:\d{8}|00\d{10}|\+\d{2}\d{8})$"
Upvotes: 1
Reputation: 8765
Try this regex:
[RegularExpression("^(\+)?(\d{2})?\d{8}$", ErrorMessage = "Invalid phone")]
Upvotes: 0