Regular expression for positive decimal number with 0, 1 or 2 decimal places

后端 未结 5 1773
终归单人心
终归单人心 2021-01-16 11:48

Please help me make regular expression for positive decimal number with 0, 1 or 2 decimal places. It must allow comma and dot. For example it must allow:

0,0         


        
5条回答
  •  感动是毒
    2021-01-16 12:14

    /^\d+([.,]\d{1,2})?$/
    

    this will properly disallow these "unformatted" numbers .01, 3., etc.

    if we have zero decimal place digits we probably as well don't want the decimal separator.

提交回复
热议问题