regex for 6 digits before and 2 digits after decimal

前端 未结 1 1826
旧巷少年郎
旧巷少年郎 2021-01-18 07:17

I need a regex in which decimal is optional. If decimal is there then there can be max 6 digits before and max 2 digits after decimal. If decimal is not there then max of 6

1条回答
  •  栀梦
    栀梦 (楼主)
    2021-01-18 07:24

    ^\d{0,6}(\.\d{1,2})?$
    

    Try this.See demo.

    https://regex101.com/r/oL9kE8/4

    Just make the (\.\d{1,2}) decimal part optional.?

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