RegEx validation for numbers only with a minimum length
23,182
Solution 1
I this will do what you're wanting.
^\d{5,}$
Solution 2
Here's a template for you:
<expression>{length}
<expression>{min,}
<expression>{min,max}
In your case it will be:
\d{5,}
See the sandbox.
Solution 3
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);
Author by
Albert Laure
Updated on August 12, 2022Comments
-
Albert Laure over 1 year
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?
-
abatishchev over 10 yearsDoesn't this mean
exactly 5
? However OP asks forat least 5
. -
Albert Laure over 10 yearsthank you sir this is what im looking for i just need to add a comma after the 5, one quick question what does $ mean?
-
abatishchev over 10 years@AsshO.Le:
^
begin of line,$
end of line. -
user3344977 over 7 yearsIf you actually want to make it mean "exactly 5" then use Bobby's original answer which he edited to properly answer the above question: ^\d{5}$ ...Adding the comma makes it minimum of 5 or greater