admin管理员组文章数量:1399297
i been searching the net for a while without any success. i appreciate if anyone can solve this problem or at least point me to the right direction.
i need a regular expression pattern that does the following:
equal or greater than the number 3
must not allow decimals
must not allow negative numbers
i am using foundation 5 abide.js to validate my form and this requires a regex pattern for advanced validation. this is required to validate a price input field.
i been searching the net for a while without any success. i appreciate if anyone can solve this problem or at least point me to the right direction.
i need a regular expression pattern that does the following:
equal or greater than the number 3
must not allow decimals
must not allow negative numbers
i am using foundation 5 abide.js to validate my form and this requires a regex pattern for advanced validation. this is required to validate a price input field.
Share Improve this question asked Sep 14, 2014 at 21:40 Ahm3dAhm3d 1294 silver badges15 bronze badges 8- 1 why regex? you have JS. – Karoly Horvath Commented Sep 14, 2014 at 21:42
- 3 Regex only? Much easier to convert to a number and check your constraints – Ruan Mendes Commented Sep 14, 2014 at 21:43
- Regexes cannot calculate, so you have to express "greater than 3" in terms of characters and strings. – georg Commented Sep 14, 2014 at 21:43
-
Also, you specified the minimum, how about the max? Is
12348712983470
a valid price? – georg Commented Sep 14, 2014 at 21:48 - 1 I love the way OPs selectively disregard questions. – Karoly Horvath Commented Sep 14, 2014 at 21:56
2 Answers
Reset to default 5As you can read in ments, regex is not the appropriate tool to deal with numbers. However you can use this pattern:
^(?:[3-9]|[12]\d)\d*$
Note: if you want to allow leading zeros, you only need to add 0*
at the begining:
^0*(?:[3-9]|[12]\d)\d*$
you could use this pattern ^(?![012]$)\d+$
Demo
here is another one for the leading zeros ^(?!0*[012]$)\d+$
Demo
本文标签: javascriptregex equal or greater than the number 3Stack Overflow
版权声明:本文标题:javascript - regex equal or greater than the number 3 - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744174173a2593920.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论