Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c#

regex

currently I am using:

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

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

Thanks in advance.

like image 817
Nick Avatar asked Feb 19 '11 10:02

Nick


1 Answers

Changing the pattern to

@"^\d{11}$"

Should do it

like image 84
Marc Gravell Avatar answered Oct 20 '22 21:10

Marc Gravell