最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Javascript regex for integer only, not to start with 0 but allow 0 - Stack Overflow

programmeradmin2浏览0评论

I need a regex to validate integer numbers. 05 and 00 are not allowed but 0 is allowed. Currently I have this:

/^[1-9]\d*$/

But it does not allow 0. Thanks for help.

I need a regex to validate integer numbers. 05 and 00 are not allowed but 0 is allowed. Currently I have this:

/^[1-9]\d*$/

But it does not allow 0. Thanks for help.

Share Improve this question asked Aug 18, 2012 at 12:17 Rafael SedrakyanRafael Sedrakyan 2,62910 gold badges36 silver badges42 bronze badges
Add a comment  | 

2 Answers 2

Reset to default 12
 ^(?:[1-9]\d*|0)$

This is your pattern...

Your regex should be ^(?!0.)\d+$

发布评论

评论列表(0)

  1. 暂无评论