Regex validation on decimal

后端 未结 2 466
一生所求
一生所求 2021-01-21 08:35

I am using the following regex to validate decimal numbers with dot .

/^[0-9]*\\.?[0-9]*$/

It works fine for all the cases except

相关标签:
2条回答
  • 2021-01-21 08:47

    Simply add one or more quantificator:

    ^[0-9]+(\.[0-9]+)?$
    
    0 讨论(0)
  • 2021-01-21 08:47

    You can use this regex:

    /^\d+(\.\d+)?$/
    

    It will match whole number: 12, 1222

    If there is a decimal point, then there must be at least 1 digit before and after the decimal point: 1.1, 34.2

    These cases are not allowed: .43, 23.

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