Regex to check if a string contains only digits and is 11 characters / digits long?

I am currently using:

if (Regex.IsMatch(searchValue, @"^\d{11}.*") && searchValue.Length == 11) { // Do something } 

How can I change the regex to also check the length, and not use the && operator?

Thanks in advance.

+7
source share
3 answers

Change template to

 @"^\d{11}$" 

Gotta do it

+7
source

Use the following expression:

^\d{11}$

+2
source

I usually use the Expresso tool to design regex patterns, especially as they get complicated. It shows a breakdown that clearly states what each bit of the regular expression does. Check out the other posters (Marc / Logicnp) for an answer to the OP issue.

+1
source

All Articles