RegEx - Exclude zero

前端 未结 6 593
抹茶落季
抹茶落季 2021-01-26 00:21

How can I exclude the 0 input in this regex? The user should be able to enter any number... but not the zero

^([0-9]*|\\d*\\.\\d{1}?\\d*)$

Than

6条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-01-26 01:00

    The following regex

    ^(?!0*(\.0+)?$)(\d+|\d*\.\d+)$
    

    Does not match

    0
    0.0
     .0
    

    But allows

      .1
     0.01
     1.00
     1.1
    01.01
    10.10
     1
    

提交回复
热议问题