how to match a number which is less than or equal to 100?

前端 未结 7 1436
耶瑟儿~
耶瑟儿~ 2020-12-03 04:35

I want to match a number which is less than or equal to 100, it can be anything within 0-100, but the regex should not match for a number which is greater than 100 like 120,

相关标签:
7条回答
  • 2020-12-03 05:32

    How about this for the regex:

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

    this would validate 7, 82, 100 for examples, but would not validate 07 or 082.

    Check this out for more information (and variations including zero prefixing) on number range checking


    If you need to cater for floating point numbers you should read this, here is an expression you can use:

    Floating point: ^[-+]?([0-9]|[1-9][0-9]|100)*\.?[0-9]+$

    0 讨论(0)
提交回复
热议问题