1

There maybe answers already with this i am not sure. but i want to setup my regex in c# to only check for a specific value. i need to understand regex better in c# any readings

I Currently have the following.

 string phoneNumberPattern = @"^\s*(?:\+?(\d{1,3}))?[-. (]*(\d{3})[-. )]*(\d{3})[-. ]*(\d{4})(?: *x(\d+))?\s*$";
 Regex phoneNumberRegex = new Regex(phoneNumberPattern);

but i only want it to be true for vaules in the following format.

18764329532
+18764329532

How do i go about fixing this?

Rand Random
  • 7,300
  • 10
  • 40
  • 88

1 Answers1

1

You can try the following :

^(\+)?\d{11}$

Explanation:

^          // should start with
(\+)?      // this makes sure + is at start only once
\d{11}    // followed by 11 digits
$         // end of line

See this working Example DEMO

Ehsan Sajjad
  • 61,834
  • 16
  • 105
  • 160