RegEx check for numbers with minimum length only

so i have this reg ex

0*[0-9]\d* 

which only accepts numbers, how could I accept only numbers, but have a minimum input of 5 numbers?

+6
source share
3 answers

I will do what you want.

 ^\d{5,}$ 
+13
source

Here is the template for you:

 <expression>{length} <expression>{min,} <expression>{min,max} 

In your case, it will be:

 \d{5,} 

See the sandbox .

+7
source

To specify the minimum number of characters, use {n,} , where n is 5 in your example, so the regex will be \d{5,}

 String pattern = @"\d{5,}"; var result = Regex.Match("12345", pattern); 
+3
source

Source: https://habr.com/ru/post/954911/


All Articles