正则表达式:如何只允许大于零的整数 [英] Regex: how to only allow integers greater than zero

查看:63
本文介绍了正则表达式:如何只允许大于零的整数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试了以下方法只允许在我的文本框中输入整数,这很好用,但它允许在那里输入零.还有什么我可以添加的以防止添加零吗?

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,并且它将只允许由数字组成的数字,即,没有句点或减号......但也没有加号、科学记数法等

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]*$

这篇关于正则表达式:如何只允许大于零的整数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆