stig
stig

Reputation: 1220

MVC 5 RegularExpression Phone Number

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

Answers (3)

Avinash Raj
Avinash Raj

Reputation: 174706

You could try the below regex,

@"^(?:\d{8}|00\d{10}|\+\d{2}\d{8})$"

Upvotes: 1

Vajura
Vajura

Reputation: 1132

[0-9]{8}|00[0-9]{10}|/+00[0-9]{11}

Upvotes: 0

Mohamad Shiralizadeh
Mohamad Shiralizadeh

Reputation: 8765

Try this regex:

[RegularExpression("^(\+)?(\d{2})?\d{8}$", ErrorMessage = "Invalid phone")]

Upvotes: 0

Related Questions