Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Regex: how to only allow integers greater than zero

Tags:

regex

I have tried the following to only allow integers in my text box, this works great but it allows a zero in there. Is there anything else I can add to prevent a zero being added?

\d+
like image 992
Funky Avatar asked Nov 15 '11 11:11

Funky


1 Answers

This will allow 10 but not 01, and it will allow only numbers consisting of digits, i.e., no periods or minus signs...but also no plus signs, scientific notation etc.

^[1-9][0-9]*$
like image 179
dnuttle Avatar answered Nov 15 '22 04:11

dnuttle