Mayur Narsale
Mayur Narsale

Reputation: 7

Validation check on Mobile number in C# and JavaScript

I am trying to do a validation check on mobile number from both C# code and Javascript.

Following should be validated OK:

I tried using:

C# code:

@"(^((([0-9]{5})|((\+[0-9]{2})[0-9]+)|((00[0-9]{2})[0-9]+))|((([0-9]{8,})|((\+[0-9]{2})[0-9]+)|((00[0-9]{2})[0-9]+))))$)"

JavaScript:

/^((([0-9]{5})|(((00[0-9]{2})|(\+?[0-9]{2}))[0-9]+))|(([0-9]{8})|(((00[0-9]{2})|(\+?[0-9]{2}))[0-9]+)))$/

With these expressions I am able to validate for 1st and last requirement but not the 2nd one (+XXxxxx).

Please help me out on this issue.

Upvotes: 1

Views: 376

Answers (1)

Yacov
Yacov

Reputation: 1070

use the OR option in the regular expression

Sample:

(\+XX)|(00)

Upvotes: 1

Related Questions