Regex: how to only allow integers greater than zero

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+

这将允许10而不是01,并且它将只允许由数字组成的数字,即没有句号或减号......但也没有加号,科学记号等。

^[1-9][0-9]*$

If you are not concerned about negatives and silly numbers like 07 , this will do:

/[1-9]d*/

For a more robust solution, I suggest converting the matched string to integer and check if it fulfills your criteria.


A minor variation is this:

/d*[1-9]d*/

That would allow leading zeros.

链接地址: http://www.djcxy.com/p/86990.html

上一篇: 用逗号分隔的正则表达式重复模式

下一篇: 正则表达式:如何只允许大于零的整数