Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RegEx validation for numbers only with a minimum length [duplicate]

so i have this reg ex

0*[0-9]\d*

which accepts numbers only how would i, make it to accepts numbers only but have a minimum input of 5 numbers?

like image 507
Albert Laure Avatar asked Sep 30 '13 02:09

Albert Laure


3 Answers

I this will do what you're wanting.

^\d{5,}$
like image 169
Bobby Cannon Avatar answered Oct 06 '22 01:10

Bobby Cannon


Here's a template for you:

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

In your case it will be:

\d{5,}

See the sandbox.

like image 41
abatishchev Avatar answered Oct 05 '22 23:10

abatishchev


To specify the minimum ammount of symbols use {n,} where n is 5 in your example, so regex would be \d{5,}

String pattern = @"\d{5,}";
var result = Regex.Match("12345", pattern);
like image 29
Dmitrii Dovgopolyi Avatar answered Oct 06 '22 00:10

Dmitrii Dovgopolyi