本文介绍了正则表达式允许零,只要它不是第一个数字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

昨天我在这里发布了一个问题正则表达式允许 null 或 1 到 9 位 在我看到我的数量字段没有取 10、100、1002 等值之后,这工作正常.因为这些值也呈现 0(零)位.所以请帮助我.

Yesterday I was posting one question here Regular Expression allow null or 1 to 9 digit This was working fine after that I saw in my quantity field not taking 10, 100, 1002 etc. value. because these values also present 0(zero) digit. So Please help me.

推荐答案

如果您想要 null 或 starts[1-9] 但可以contain [0-9],模式为

If you want null or a number that starts from [1-9] but can contain [0-9], the pattern is

 (^[1-9][0-9]*$)|(^$)

请注意,单个零是不允许的:0 不匹配.如果您也想匹配它(您想要一个空字符串 - 0数字必须从 [1-9] 开始并且可以包含 [0-9])

please, notice that a single zero is not allowed: 0 doesn't match. In case you want to match it as well (you want a empty string, zero - 0 or a number which must start from [1-9] and can contain [0-9])

 (^[1-9][0-9]*$)|(^0?$)

这篇关于正则表达式允许零,只要它不是第一个数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-26 19:11